Event for no records

Event for no records

UngarMaxUngarMax Posts: 4Questions: 0Answers: 0

Hello,

I would like to know whether there is an event that is triggered when there are no records (retrieved by AJAX, for e.g.). I am willing to not render the datatable so I can show a custom message of my own instead.

Thanks.

Replies

  • UngarMaxUngarMax Posts: 4Questions: 0Answers: 0

    Bump.

  • allanallan Posts: 61,879Questions: 1Answers: 10,138 Site admin

    There is no event for that as such - you would need to use draw and then use page.info() to check how many records there are.

    Allan

  • UngarMaxUngarMax Posts: 4Questions: 0Answers: 0
    edited July 2016

    @allan Ok, thanks for your answer! Would it be possible to prevent the table from drawing in draw so it is not showed? (So I can draw a bootstrap alert instead).

    Would a return false do the trick?

  • allanallan Posts: 61,879Questions: 1Answers: 10,138 Site admin

    No - the draw event happens at the end of the draw to inform you that the table has been drawn. I guess you could hide the table at that point and show a Bootstrap alert if that is what you need tho.

    Allan

  • UngarMaxUngarMax Posts: 4Questions: 0Answers: 0

    Awesome, didn't think about that. I think this could be a new feature implemented in future versions.

  • allanallan Posts: 61,879Questions: 1Answers: 10,138 Site admin

    The problem with that is that there should then be an event for just 1 record, 2 records, etc. Having the draw event with a single call to the API to get the required information is a nice simple generic way of doing it.

    Allan

This discussion has been closed.