1

I have datatables using ajax as data source, also I have an array contains several row_id , I would like to show rows which row_id is not in this array.

How can I do it?

I have search datatables doc, and tried many functions/callbacks, neither of them works.

1 Answer 1

1

You can very easily set up a custom filter that permanently exclude (or hide) certain rows after any criteria you want :

var excluded_row_ids = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]

$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
   //assuming the row_id is located in first column
   return (!~excluded_row_ids.indexOf(parseInt(data[0]))) 

   //or for example compare to dataIndex, i.e. original insert order
   //return (!~excluded_row_ids.indexOf(dataIndex))
})

If you for some reason want to include the excluded rows, simply remove the filter :

$.fn.dataTable.ext.search.pop()

demo -> http://jsfiddle.net/pcwf6tuh/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.