Exclude Column from Search

Exclude Column from Search

JamieStantonJamieStanton Posts: 4Questions: 0Answers: 0
edited October 2010 in General
Hi

I'm wondering if there is a way to tell DataTables to not search a certain column. I am creating a directory for shops in Dublin, but users will want to filter by Postcode (ie. Dublin 7). However at present it is also taking into account phone numbers, giving inaccurate results. Can I tall it to not filter a certain column?

Many thanks for your help

Jamie

Replies

  • mstrandmstrand Posts: 24Questions: 0Answers: 0
    It is possible to exclude columns from the search by using "bSearchable": false.

    See the bSearchable example here:

    http://www.datatables.net/usage/columns
  • JamieStantonJamieStanton Posts: 4Questions: 0Answers: 0
    Hey thanks. I've added some of this example code but am having some trouble getting it to work. I wanted to disable the fourth column so altered the code accordingly, however this makes dataTables cry.

    [code]/* Using aoColumns */
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumns": [
    null,
    null,
    null,
    { "bSearchable": false }
    ] } );
    } );[/code]

    Clearly I am doing it wrong. Excuse my n00bishness as I don't' normallycode in JS / JQ.
  • mstrandmstrand Posts: 24Questions: 0Answers: 0
    I can't spot anything wrong with the code you posted. Are you getting an error message that might indicate the problem?

    Matthew
  • JamieStantonJamieStanton Posts: 4Questions: 0Answers: 0
    edited October 2010
    Hey. My error message is thus:

    DataTables warning (table id = 'example'): Cannot reinitialise DataTable.

    To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destory the old table and create a new one, set bDestroy to true (note that a lot of changes to the configuration can be made through the API which is usually much faster).

    And the full code calling in DataTables is:

    [code]


    $(document).ready(function() {
    $('#example').dataTable( {
    "sPaginationType": "full_numbers"
    } );
    } );

    /* Using aoColumns */
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumns": [
    null,
    null,
    null,
    { "bSearchable": false }
    ] } );
    } );

    [/code]
  • mstrandmstrand Posts: 24Questions: 0Answers: 0
    You should only have the [code]$('#example').dataTable( { [/code] section once. Try removing the first block:

    [code]
    $(document).ready(function() {
    $('#example').dataTable( {
    "sPaginationType": "full_numbers"
    } );
    } );
    [/code]

    and see if dataTables is happier then.
  • JamieStantonJamieStanton Posts: 4Questions: 0Answers: 0
    That works great now. Many thanks for your help. Clearly I have much to learn ;-)
This discussion has been closed.