2

Hello I would like to filter my items in my datatable by select input. But when I filter it, datatables uses AND method. I would like to filter my items with OR.

The point is when I choose HOME and WORK filter in select input it must display me items from HOME or WORK category (not items which are in home and work category both like is now).

The HTML Code:

    <h4>Select your multiple filter</h4>
<div>
    <select id="select-category" name="categories" multiple>
        <option value="">All</option>
        <option value="Home">Home</option>
        <option value="Work">Work</option>
        <option value="City">City</option>
    </select>
</div>
<div>
    <h4>Table of items</h4>
    <table>
        <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Category</th>
        </tr>
        </thead>
        <tbody>
            <tr><td>1</td><td>Lamp</td><td>Home</td></tr>
            <tr><td>3</td><td>Desk</td><td>Work</td></tr>
            <tr><td>2</td><td>Books</td><td>Home</td></tr>
            <tr><td>3</td><td>Cars</td><td>City</td></tr>
            <tr><td>3</td><td>Desk</td><td>Work</td></tr>
            <tr><td>3</td><td>Photocopying</td><td>Work</td></tr>
            <tr><td>3</td><td>Clip</td><td>Work</td></tr>
            <tr><td>3</td><td>Street</td><td>City</td></tr>
         </tbody>
    </table>
</div>

The JS Code:

var dataTable = $('table').dataTable();
$('#select-category').change( function () { 
    dataTable.fnFilter( $('#select-category').val(),2);
});

Here is my jsfiddle link with my example of filtering with AND, which i want to change to OR.

http://jsfiddle.net/Z6uQ2/13/

4

0

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.