Column search not working server side - How to debug?

Column search not working server side - How to debug?

EnaldiEnaldi Posts: 6Questions: 2Answers: 1

I'm working on an intranet site and can't link to my code, but maybe someone can see an error or suggest how I might debug this.

My table gets its data server-side, and normally searching works. But I'm unable to limit a programmatic search to one column; the search term is not getting passed at all in that case, and no errors are generated (and the entire table is returned).

For example, searching the entire table, like this, does work:

orgTabTable.search(_orgId).draw();

But this does not work:

orgTabTable.column({name: 'OrgID'}).search(_orgId).draw();

Neither does this:

orgTabTable.column( 1 ).search(_orgId).draw();

in both of those non-working cases, my server is not receiving the search term, eg:

{
"data": "ORGID",
"name": "OrgID",
"searchable": true,
"orderable": true,
"search": {
"value": "",
"regex": false
}
},

No errors are being generated, including in the console.

Any ideas?

Thanks in advance!

This question has accepted answers - jump to:

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    I did not do it that way. I appended the search criteria to the existing structure that is passed to the server in the ajax:data function so it looks something like this:

    $("example").DataTable({
        serverSide:true,
        ajax:{url:"mypath",
                data:function(parms) {
                    // user picks column name from select box
                    var colNum = parseInt($("#sel").val());
                   // the search value from a text box
                  var val = $("#txt").val();
              
                  parms.columns[colNum].search.value = val;
                  return parms;
    
                   
               }
    
    }
    }) 
    
    
    

    If you use the name options as you did in your code, you can search through columns until you find parms.columns[x].name == "columnName"

  • allanallan Posts: 64,756Questions: 1Answers: 10,715 Site admin
    Answer ✓

    I think the issue is the column selector - there is no { name: ... } option (that will be getting passed to the selector-modifier.

    Instead use:

    orgTabTable.column('OrgID:name')....
    

    The full list of options for the column selectors are available in the column-selector documentation.

    orgTabTable.column( 1 ).search(_orgId).draw();

    That's odd. Does _orgId definitely have a value?

    Allan

  • EnaldiEnaldi Posts: 6Questions: 2Answers: 1
    edited May 2017

    Thank you, Allan!!! After fixing the syntax mistake, I was able to get it to work with the column name.

    And thank you @bindrid! I also got your approach to work, and I may use it in the future.

This discussion has been closed.