Search on rows attributes

Search on rows attributes

EmyleenEmyleen Posts: 21Questions: 8Answers: 0

Hello!

I'm trying to make a search engine on my datatable, and I have a problem.
I have a multiple select in my search engine and when some options are selected I want to filter my datatable. But now I don't see how! Can you help me?

This is my code :

http://jsfiddle.net/mgzqcfc2/

Thank you!

This question has an accepted answers - jump to answer

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Your going to need to integrate that code sample into a fully functioning example (with some comments explaining your custom code) so we can better understand it.

  • EmyleenEmyleen Posts: 21Questions: 8Answers: 0

    This is more part of my code http://www.bootply.com/1SsZwFgwXT

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Thanks for the example. Unfortunately I do not understand how the code logic, so I can't answer the question. I think I almost understand it.Can you describe how the user would use the search engine and what results you expect?

  • EmyleenEmyleen Posts: 21Questions: 8Answers: 0
    edited September 2015

    In fact the user can select multiple choices in the drop down list, and when he selects a choice (on the change of the select) it must "filter" the display of the DataTable.

    In my code i want to search() only on rows that are in rowlist :

    $datatable.DataTable()
    .rows(rowlist)
    .search(search)
    .draw();

    But this code doesn't work :/
    rowlist is an array that contains element of the DOM, the rows that I want in the DataTable.

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

    Yes you can search on cell attributes - see the orthogonal data documentation.

    Allan

  • EmyleenEmyleen Posts: 21Questions: 8Answers: 0

    Ok... but I preferred to look on row attributes because my rows looks like that :

    <tr data-attr1="1,25,6" data-attr2="2,85,4,0">...</tr>

    Too bad... I'll manage otherwise. Thanks anyway.

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    Answer ✓

    if the attributes contain row numbers, then you would convert that to an array and use it as a selector for rows().

    http://datatables.net/reference/api/rows()

    If the attributes contain row IDs, then you should still be able to convert list of IDs into an array and use that as a selector

    http://datatables.net/reference/type/row-selector - see the section on "string - #ID"

    For my Row ID I use a created column that is "ID" + the real ID, ID1, ID2, ID3, etc. This helps me understand what value I'm looking at when I debug.

    from the documentation:

    var rows = table.rows( [ '#ID2', '#ID5' ] );
    
    

    Hopefully you can see how to adapt this to your code.

This discussion has been closed.