"No matching records found" is premature?

"No matching records found" is premature?

pdxrlkpdxrlk Posts: 3Questions: 0Answers: 0
edited October 2009 in General
Hi - first off, very nice plugin!

I am using DataTables to fetch server-side information via Ajax (client side processing, but server-side data using sAjaxSource). The functionality of DataTables seems fine, however there is a usability issue I'd like to correct if possible.

The server queries may take a few seconds, and loading the data may take a few seconds. When I initialize the datatable it immediately displays with "No matching records found" (and the Processing... indicator is also shown). Once the data is loaded the "No matching records found" line is replaced with the data rows.

This seems to be a usability issue - my users will not be sophisticated, and they will sit there for perhaps five to ten seconds wondering why searching for Smith returned zero results, and worse, perhaps submit additional searches to try to correct.

Is there any way to disable the No Matching Records Found message until after the Ajax call completes?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi pdxrlk,

    Thanks! Good to hear that DataTables is going down well!

    What I would suggest in this case is that you make use of the internationalisation options that DataTables presents and a little 'trick' :-)

    [code]
    $('#example').dataTable( {
    "oLanguage": {
    "sZeroRecords": "Please wait - loading data from server"
    },
    "fnInitComplete": function ( oSettings ) {
    oSettings.oLanguage.sZeroRecords = "No matching records found"
    }
    } );
    [/code]
    So what is happening here is that you are setting a custom string at initialisation time to state that data is loading, but once that initialisation is complete the fnInitComplete() function will set it back to the text you might expect.

    Regards,
    Allan
  • pdxrlkpdxrlk Posts: 3Questions: 0Answers: 0
    Perfect, works like a charm. Thanks!
  • pdxrlkpdxrlk Posts: 3Questions: 0Answers: 0
    Well - this doesn't quite work perfectly after all. Debugging a problem with the following sequence of events:

    1. Initialize the table, as above.
    2. Load the table with an Ajax call. Please Wait is displayed as expected, and No matching records found is displayed as well.

    3. fnReloadAjax called for another query. This time no progress indicator is displayed.

    So I added the following line before the call to fnReloadAjax:
    myTableSettings.oLanguage.sZeroRecords = "Please wait - searching...";

    Now the problem is that if my query returns zero results, then the progress indicator never goes away. Worse, there does not seem to be any callback which I can hook into which would allow me to reset the progress indicator (fnRowComplete, for example, is never called if there are no rows returned).
  • anabelleanabelle Posts: 2Questions: 0Answers: 0
    I am trying to achieve the same thing.

    Currentle I load the data when de table initializes because it should display different data depending on the logged in user on my aplication.

    It works nice when waiting for the data to load. But as I am not using serverside search, but just as a live filter, if a search doesn't display any results, the Loading... text stays there forever.

    How can this be solved?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    @pdxrlk: Perhaps the correct thing to do would be to use bProcessing - http://datatables.net/usage/features#bProcessing . You can style this using CSS to cover the table (nice little loading graphics etc) which might do the trick for you? This is specifically what bProcessing what in there for.

    @anabelle: Sounds like a different problem. You can't use server-side processing and client-side filtering. For example if the data is over multiple pages, then DataTables doesn't know anything about the data on the pages other than the currently displayed one, and thus the filter must be done at the data source - http://datatables.net/usage/#data_sources

    Allan
This discussion has been closed.