Custom search for non-string value columns

Custom search for non-string value columns

raihaniqbalraihaniqbal Posts: 1Questions: 1Answers: 0
edited July 2021 in DataTables 1.10

Assuming I have the following dataset:

var myDataSet = 
[
   {
      "SimpleProperty1":"Value1",
      "ComplexProperty2":[
         {
            "SubProperty1":"SubValue1",
            "SubProperty2":"SubValue2"
         }
      ]
   }
];

Is there a way to specify a custom (override) function for search when I define the columns the same we do for render?

Something like this:

$('#live_table').DataTable({
   dom: 'lfrtip',
   data: myDataSet,
   columns:[
   {
       title: "Property 1",
       data: "SimpleProperty1"
   },
   {
       title: "Property 2",
       data: "ComplexProperty2",
       render: function(){
               // custom render logic
       },
       search: function(){
               // custom search logic to loop through the array
       }
   }
   ]

Answers

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

    Hi,

    The columns.render function will pass in (as the second attribute) information about what kind of data it is requesting. For search data it will pass in filter which you can check for with an if and then return the data as you need.

    More information about this available in the orthogonal data part of the manual.

    Allan

Sign In or Register to comment.