Output filtered results

Output filtered results

flowteflowte Posts: 21Questions: 6Answers: 0

I want the user to be able to use the filters on a datatable to get a particular list and then output the ids of each row of the list to a javascript / jquery / ajax function to do something with it. Is this possible?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I don't see why not. Use columns().search() for a column level filter and rows().ids() to get the ids.

    Allan

  • flowteflowte Posts: 21Questions: 6Answers: 0

    would I use that as part of an external function?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    To be honest I'm not sure what that means. Those are the API methods that you would call to trigger searching on columns and also to get the ids of rows.

    Allan

  • flowteflowte Posts: 21Questions: 6Answers: 0

    What I'm trying to do is allow the user to use the filters on the datatable and when they have a list as they want it to click a button on the screen which then makes use of all ids for each row and pass them through a separate function

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Did you look into rows().ids(). That sounds like exactly what you want. Get the ids of the rows in the table when your click event is activated.

    Allan

  • flowteflowte Posts: 21Questions: 6Answers: 0

    I'm using it but what it is outputting is all ids prior to filtering. i.e. I start with 30 items on the list, use filters which then displays 5 items but when I use the rows().ids() it outputs all 30 items. Am I missing something?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    You need to use the selector-modifier option to get only the filtered rows:

    table.rows( { search: 'applied' } ).ids();
    

    Allan

  • flowteflowte Posts: 21Questions: 6Answers: 0

    gerr, hate when it is something simple. Thanks for your help!

This discussion has been closed.