Datatables flitering and search button

Datatables flitering and search button

FRS4002FRS4002 Posts: 85Questions: 11Answers: 0

How can I filter only specific columns like for example column 3 and 4 when searching?

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    You can disable searching in specific columns with columns.searchable - see example here: http://live.datatables.net/bilofufi/1/edit

    Colin

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0

    @colin Thanks! It worked! But what if I need also to do
    columnDefs: [{
    targets: 3,
    render: function (data, type, row){
    if (type === 'filter'){
    return data.replace(/e/g, 'i');
    }
    return data.replace();
    }
    }
    ],
    I need to merge both, how?

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited January 2022

    Just add searchable: false, like this:

    columnDefs: [{
      targets: 3,
      searchable: false,
      render: function (data, type, row){
      if (type === 'filter'){
        return data.replace(/e/g, 'i');
      }
      return data.replace();
      }
    }
    ],
    

    To properly use Markdown place the three back ticks on their own line. One set at the beginning of the code snippet and another at the end. You don't need them on each line. Like this screenshot:

    The js is for Javascript formatting. Read more about it here.

    Kevin

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0

    @kthorngren Nope. That's not what I need. I need target 3 for replace and targets 0,1,4 for searchable false. How can I do that?

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    Add another object to columnDefs like this:

    columnDefs: [{
      targets: 3,
      render: function (data, type, row){
      if (type === 'filter'){
        return data.replace(/e/g, 'i');
      }
      return data.replace();
      }
    },
    {
      targets: [0, 1, 4],
      searchable: false
    }
    ],
    

    Kevin

  • FRS4002FRS4002 Posts: 85Questions: 11Answers: 0

    @kthorngren Perfect! It worked! Thanks!

Sign In or Register to comment.