Column search value not in AJAX request

Column search value not in AJAX request

pdugaspdugas Posts: 13Questions: 4Answers: 2

Trying to add column footer filters - an input for one and a select for another. The controls are there and the "change" callbacks are being called but the resulting AJAX requests don't include the given search values. Surely I'm missing something silly...

Here's the code that's attaching the callbacks:

      initComplete: function() {
        var api = this.api();
        $('input', api.column('name:name').footer()).on('keyup change', function() {
            if (api.column('name:name').search() !== $(this).val()) { 
                console.log('Setting filter on NAME to "'+$(this).val()+'"');
                api.column('name:name').search($(this).val()).draw(); 
            }
        });
        $('select', api.column('status:name').footer()).on('change', function() {
            console.log('Setting filter on STATUS to "'+$(this).val()+'"');
            api.column('status:name').search($(this).val()).draw();
        });
      }

I'm getting the "Setting filter..." messages in the console but the AJAX server is getting a request with a query like below. This is from the browser's Developer Tools / Network info. Note columns[0][search][value] and columns[3][search][value] are empty still.

draw:6
columns[0][data]:name
columns[0][name]:
columns[0][searchable]:true
columns[0][orderable]:true
columns[0][search][value]:
columns[0][search][regex]:false
columns[1][data]:description
columns[1][name]:
columns[1][searchable]:true
columns[1][orderable]:true
columns[1][search][value]:
columns[1][search][regex]:false
columns[2][data]:route
columns[2][name]:
columns[2][searchable]:true
columns[2][orderable]:true
columns[2][search][value]:
columns[2][search][regex]:false
columns[3][data]:status
columns[3][name]:
columns[3][searchable]:true
columns[3][orderable]:true
columns[3][search][value]:
columns[3][search][regex]:false
order[0][column]:0
order[0][dir]:asc
start:0
length:50
search[value]:
search[regex]:false
_:1477056635349

Using the search field for the whole table results in the search[value] being set as expected and the back-end is responding accordingly. I just can't see to figure out what I'm missing to get the column search fields populated. My guess is that the way I'm getting the column isn't correct.

I'm using version 1.10.12.

Answers

  • pdugaspdugas Posts: 13Questions: 4Answers: 2

    So, it works if I use integer indexes as the parameters to the column() calls on lines 6 and 11. Using the :name parameters works elsewhere but not there. Curious.

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    How odd! Are you able to give me a link to the page so I can take a look into that? Or possibly, could you try the nightly version of DataTables as there have been a couple of changes in the selectors.

    Thanks,
    Allan

  • pdugaspdugas Posts: 13Questions: 4Answers: 2

    I've refactored by code and am now iterating through columns().every() and looking in footer() for an INPUT or a SELECT and attaching the event handlers. The column is in "this" now. Don't have an example to point you to. Sorry.

This discussion has been closed.