Using searchCols for server-side processing on 1.10

Using searchCols for server-side processing on 1.10

ghukillghukill Posts: 4Questions: 1Answers: 0

I've spent time recently familiarizing myself with Datatables, found the server-side approach perfect for our large results sets. But something I can't seem to trigger is searching / filtering on ONE column for the results set. The option searchCols looks perfect, but I can't seem to have it push values to columns[1][search][value], the column I'd like to search on.

Example code for searchCols:

$('#example').dataTable( {
"searchCols": [
    null,
    { "search": "My filter" },
    null,
    { "search": "^[0-9]", "escapeRegex": false }
  ]
} );

My code, thinking this array provided in searchCols would search the 2nd column:

$(document).ready(function(){           
    $('#example').DataTable( {      
        "serverSide": true,     
        "ajax": 'http://hostname-here/cgi-bin/php_simple.php',
        "searchCols":[          
            null,
            { "search" : "smalluser" }
        ]               
    } );    
});

Any suggestions? Am I missing something simple? I spent considerable time wrapping my head around the changes between 1.9 - 1.10, and decided to embrace the 1.10 as I hope to use this moving forward with my project. If I change the GET parameter "columns[1][search][value]=smalluser" manually, it behaves as expected; what am I missing about using searchCols as a parameter in launch?

Many thanks.

Answers

  • ghukillghukill Posts: 4Questions: 1Answers: 0

    I should clarify - I cannot get search terms to show up in the GET parameters using init options. When I enter them manually in a URL and hit the server-side script, it works beautifully. I've gotten "search":{"search":"smalluser"} to work, but that operates on all columns...

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
  • ghukillghukill Posts: 4Questions: 1Answers: 0
    edited May 2014

    Thanks for responding. Unfortunately, I don't think so. I'd like to limit the records coming out of MySQL before they hit the browser. Let's say I've got 10,000 rows in SQL, I'd like to filter on a column and return let's say 1000 for a given user.

    I could be wrong, but this looks like filtering client-side after the results set have been returned?

  • KenSKenS Posts: 1Questions: 0Answers: 0

    I am having the same issue. Defining "searchCols" does not seen to have any affect.

  • sectoradsectorad Posts: 2Questions: 0Answers: 0

    I'm having the same problem.. searchCols does not seem to behave as expected.
    There doesn't seem to be any way of setting initial per column search values when using server-side processing.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    It looks like there is an error with the Hungarian to camelCase translation for searchCols. Using the old Hungarian notation works: http://live.datatables.net/waselab/1/edit . I'll look into making the camelCase also work.

    Allan

  • sectoradsectorad Posts: 2Questions: 0Answers: 0

    Works like a charm. Thanks.

  • ghukillghukill Posts: 4Questions: 1Answers: 0

    Works like a charm indeed, thanks Allan.

This discussion has been closed.