How can I determine if a match was found using fnFilter

How can I determine if a match was found using fnFilter

jfb1234jfb1234 Posts: 10Questions: 0Answers: 0
edited March 2012 in General
I've been using this great plugin for a couple of days now with much success, but have now run into something I can't figure out. I need to make a decision based on whether or not a match was found in a table. I don't need to know what the results are, just if there was a match.

Thanks, Jim

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    http://datatables.net/plug-ins/api#fnPagingInfo - iFilteredTotal might do the job for you. You can put that into fnDrawCallback which is called after every filter.

    Allan
  • jfb1234jfb1234 Posts: 10Questions: 0Answers: 0
    Allan,

    iFilteredTotal does what I need.

    Thanks, Jim
  • jfb1234jfb1234 Posts: 10Questions: 0Answers: 0
    Allan,

    Just for info purposes. After a little testing I found that I don't need to use fnDrawCallback. The following code works without it.

    [code]/* Callback to submit a validated addItemForm */
    function addItemFormGood() {
    var optionsAdd = {
    target: '#msgArea',
    clearForm: 'true',
    success: addItemFocus
    };
    $('#namesTable').dataTable().fnFilter($('#phoneNumberEast').val());

    if (oNamesTable.fnPagingInfo().iFilteredTotal == 0){
    alert('no match');
    } else {
    alert('match');
    }
    return false;} [/code]

    Regards, JIm
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Looks good - thanks for the update :-)

    One thing to note for yourself or anyone else who finds this in future, if using server-side processing fnFilter() is async - so this probably wouldn't work, you'd need to use a callback function, since the following logic would run before the new data has been loaded.

    Perfect for client-side processing though!

    Allan
This discussion has been closed.