0

I have a table that is being populated by way of a repeater and I have added the relevant dataTable .css and .js to enable the plugin. This works fine and as expected. The issue I am having is how can I now enable a few 'filter buttons' which when clicked apply a string based filter to the table data. I can simulate what I want by using the actual Search Bar that you can enable, but I would prefer to have some anchor tags that serve as clickable buttons/filters to trigger this.

Example Table

ID :  Type   
----------
1  :  Car
2  :  Car
3  :  Bike
4  :  Bike
5  :  Car

The javascript at the bottom of the page looks like this:

var table = $('#example').DataTable();

var filteredData = table
    .columns( [0, 1] )
    .data()
    .flatten()
    .filter( function ( value, index ) {
        return value = 'Bike' ? true : false;
    } );

I suspect there is an issue with how I am defining my search criteria, and in the example above this is attempting to set a filter on anything within columns 0 or 1 that contain the string 'Bike'.

Any help would be greatly appreciated.

1 Answer 1

4

Try this:

var table = $('#example').DataTable();
    table.columns( [0, 1] )
        .search('Bike')
        .draw();

Reference: https://datatables.net/reference/api/column().search()

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

1 Comment

Appreciate the response and this has worked well for my purposes.Thank you, Mohsin.

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.