Remove "(filtered from NaN total entries)"

Remove "(filtered from NaN total entries)"

Seb33300Seb33300 Posts: 3Questions: 1Answers: 0

Hello,

I am using Datatables to render multiple tables in my application using ajax (server side processing).

But in some case, for performance reason, I don't send the recordsTotal so the "(filtered from NaN total entries)" appear below the datatable.
Is there a way to hide it only when the recordsTotal is not given? (I don't want to remove it from all my Datatables)
Ortherwise replace "NaN" by something like "unknown"?

Seb

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30
    edited November 2017

    Try experimenting with infoCallback option as shown below.

    infoCallback: function(settings, start, end, max, total, pre){
        return (!isNaN(total))
            ? "Showing " + start + " to " + end + " of " + total + " entries"
               + ((total !== max) ? " (filtered from " + max + " total entries)" : "")
            : "Showing " + start + " to " + (start + this.api().data().length - 1) + " entries";
    }
    

    See this example for code and demonstration.


    See more articles about jQuery DataTables on gyrocode.com.

  • Seb33300Seb33300 Posts: 3Questions: 1Answers: 0

    Thanks, but I need to keep translations (my application could be displayed in multiple languages).
    Can I use texts from the translation files with this solution?

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Yes, use language.infoFiltered to remove the _MAX_ property.

    Note that DataTables does expect the recordsTotal to be returned!

    Allan

  • Seb33300Seb33300 Posts: 3Questions: 1Answers: 0

    I'm sorry but I'm not sure to understand.

    I don't want to remove the _MAX_ property.
    I am looking for a way to hide the infoFiltered message if recordsTotal is null.

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30

    It could be possible to add your own key to the language property and use i18n method to access it in customized infoCallback function.

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Yup - infoCallback is the only way to handle the case where it might be null or might be a number. However, as I noted, this is not something that DataTables expects - it is not a supported use case.

    Allan

This discussion has been closed.