How To Filter On Input Value Text

How To Filter On Input Value Text

roadjanroadjan Posts: 22Questions: 6Answers: 0
edited May 2022 in DataTables

Hi,

I am using buttons for quick filters on my datatable. It works for columns containing text using this code. How do I filter based on the value text of an input in the column (i.e. the button text of a button in the column).

                      function filterColumnC( value ) {
                        table.column(3).search( value ).draw();
                      }                                                    

                    $('button#quote').on('click', function () {
                        filterColumnC('quote');
                      })  

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Do something similar. Create an event handler for the buttons in the table. Use delegated events, like this example. In the event handler get the clicked button's text and use column().search().

    Kevin

  • roadjanroadjan Posts: 22Questions: 6Answers: 0

    Sorry, I am not being clear. My code searchs column#3 for a 'value' which is passed to the function, in this case the value is 'quote'. How do I alter the function to look for the text value of the button, rather than then text 'quote'. It is not recogising the button value 'Create Invoice' as text, and therefore returns no results.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Use standard jQuery methods to get the text. Something like this maybe?

    $('button#quote').on('click', function () {
        filterColumnC( $(this).text() );
      })
    

    Kevin

Sign In or Register to comment.