Custom search on server side processing

Custom search on server side processing

jerry_incjerry_inc Posts: 3Questions: 1Answers: 0

Hi, I am trying to implement a custom search, and data is coming via ajax but having some trouble...

this is my code

dataTableVar = $('#example').DataTable({
       "serverSide": true,
       "processing": true,
       "searching": true,
       "dom": '<"recordsFilterDD"><"dtTop"Bp>rt<"clear">',
        "pageLength": DEFAULT_PAGE_LENGTH,
         "ajax": {
                  "url": "?g=session_data_ajax",
                  "type": "POST"
          },
           "language" : {....}, // reduced code
           "buttons": [{....}]   // reduced code
});

I want to search only on two columns and I am not using default search. so I am getting search keyword from custom input box. I can search on one column like this...
dataTableVar.columns(2).search.(this.value).draw();

How can I search multiple columns?

If I try the following code, it doesn't work...

$.fn.dataTable.ext.search.push(
         function (settings, data, dataIndex) {
                 console.log("This code Worked!");
         }
);

I also tried this... but it also didn't work

$.fn.dataTableExt.afnFiltering.push(
         function (oSettings, aData, iDataIndex) {
                  console.log("This code Worked!");
          }
 );

Answers

  • jerry_incjerry_inc Posts: 3Questions: 1Answers: 0

    Let me explain some more....

    The user will enter search keywords like this...

    column_1 = "Hello" column_2 = "world" etc

    so I want to search

    "hello" in column_1
    and
    "world" in column_2

  • jerry_incjerry_inc Posts: 3Questions: 1Answers: 0

    I have solved it.

    Solution is following

    dataTableVar.columns(2).search.(this.value);
    dataTableVar.columns(3).search.(this.value);
    dataTableVar.draw();
    

    This will search only in two Columns. with AND operator

This discussion has been closed.