$.fn.dataTable.ext.search.push

$.fn.dataTable.ext.search.push

rf1234rf1234 Posts: 632Questions: 37Answers: 100

Hi!
I ran into the same problem as described here: https://datatables.net//forums/discussion/comment/90255/#Comment_90255
settings.nTable.id didn't really work, I didn't find it. What I did is this:

$.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
        //we only do this for the second table
        if (settings.sTableId === 'tblInboxOfferGov') {
            var ok;
            ok = filterShowNMonths(data, ixUpdateTime);
            if (ok) {
                return filterDeleted(data, ixDelete);
            } else {
                return ok;
            }
        } else {
            return true;
        }
    }
);

Is there a better way to do this? Or is that what you would also recommend? Will settings.sTableId be around for a while?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 632Questions: 37Answers: 100
    Answer ✓

    Found a better solution. In a different example I saw that you are also passing the database row to the function above. For that reason I changed my approach. I am no longer working with the search data (which is a nuisance anyway because this only works if you know the field index which changes when you change the field sequence in the table) but I work with the row data. Don't need settings.sTableId any longer.
    This is what it looks like right now:

     $.fn.dataTable.ext.search.push(
        function( settings, data, dataIndex, row, counter ) {
            //we only do this for the second table
            if ( (typeof row.offer !== 'undefined') &&
                 (typeof row.offer_has_govdeptview !== 'undefined') )   {
                if (row.offer_has_govdeptview.deleted !== null) {                    
                    var ok;
                    ok = filterShowNMonths(row.offer.update_time);
                    if (ok) {
                        return filterDeleted(row.offer_has_govdeptview.deleted);
                    } else {
                        return false;
                    }
                }
            }
            return true;
        }                
    );
    
  • juancarlos77juancarlos77 Posts: 3Questions: 2Answers: 0

    Hi, could you tell me where they come from and what they are

    settings, data, dataIndex, row, counter

  • kthorngrenkthorngren Posts: 2,970Questions: 19Answers: 668

    Here is the doc for the search plugin:
    https://datatables.net/manual/plug-ins/search

    Kevin

Sign In or Register to comment.