no data available when i istantiate a new table

no data available when i istantiate a new table

vismarkvismark Posts: 79Questions: 5Answers: 0
edited October 2017 in Free community support

I have this situatuation:
- DataTable in the main body
- DataTable in a bootstrap modal-body (rendered on modal open)

Problem is that when I render the table in the modal, this will have no data in it because of some filter wrongly applied (i see "0 results filtered from N total" in the info div). In fact, if i set "searching" option to false, i regularly see the rows of the table. I think the filters from the table in the main body are interfering with the modal table. This is strange because the modal table is being freshly created...what can i check or how can i fix this issue?

Replies

  • timcadieuxtimcadieux Posts: 76Questions: 22Answers: 0

    Need to see it

  • vismarkvismark Posts: 79Questions: 5Answers: 0

    Found the point.

    I have custom column filters enabled. I use this code to filter by numeric range:

    var filterByNumericRange =  function(column, min, max) {
        $.fn.dataTableExt.afnFiltering.push(
            function(oSettings, aData, iDataIndex) {
                var data = parseFloat(aData[column]) || 0;
    
                if (
                    (isNaN(min) && isNaN(max)) ||
                    (isNaN(min) && data <= max) ||
                    (min <= data && isNaN(max)) ||
                    (min <= data && data <= max)
                ) {
                    return true;
                } else {
                    return false;
                }
            }
        );
    };
    

    and when the page loads, i activate the filter with this:

    filterByNumericRange(interestedColumn, tdContainingTheFilter);
    table.draw();
    

    If I disable this filter, the modal table is shown correctly. What is wrong with it? I think it is filteriing the given column on the whole DataTable objects available...how can i restrict it?

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

    You need to add a check into the filtering function:

    function ( settings, data, index ) {
      if ( settings.nTable.id !== 'tableIdOfInterest' ) {
        return true;
      }
    
      var data ....
    }
    

    This is a weakness in the filtering plug-ins for certain. Something I'm going to address in a future update.

    Allan

  • vismarkvismark Posts: 79Questions: 5Answers: 0

    thanks Allan!

This discussion has been closed.