• Resolved jptoews

    (@jptoews)


    Using the Search field above the table, all columns are searched. Is there a way to restrict this search to a single column? I see that you have an extension which provides a drop-down menu for each column, but I’ve got a table with close to 1500 rows, and each value in the desired column is unique (or nearly so), making a drop-down menu not feasible.

    https://www.ads-software.com/extend/plugins/tablepress/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question.

    I see two possibilities here:
    1.) You could use a different TablePress Extension from https://tablepress.org/extensions/datatables-column-filter/ that adds a text field for each column, as can be seen on https://jquery-datatables-column-filter.googlecode.com/svn/trunk/default.html

    2.) You could stick with the one search field above the table and restrict that to a single column. To do that, you’ll need the following to the “Custom Commands” textfield on the table’s “Edit” screen:

    "aoColumnDefs": [ { "bSearchable": false, "aTargets": [ "_all" ] }, { "bSearchable": true, "aTargets": [ 2 ] } ]

    That code has two parts: The first part disables searchability for all columns, and the second part restored it for the third column,indicated by the “2”, as counting starts with 0. So, you’ll just have to change the “2” to the column number minus one for the column that you want to be searchable.

    Regards,
    Tobias

    Thread Starter jptoews

    (@jptoews)

    Option 2 is exactly what I want… but it doesn’t seem to work for me. I changed the column number to 0, since I only want to search the first column (name), but no matter what value I enter in the Search field, I get a “No matching records found” message.

    Just in case, I tried changing the column number in your code to various other columns, then tried to search for values that I know exist in the specified column. Every search returned the “No matching records found” message.

    You can see the table here:

    https://dev.studiotwo.com/jttest/sample-page/

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    hmm, strange. Then I assume that the idea of prohibiting search for all columns and re-enabling it for the first column does not work.
    We will then need to just prohibit search for all columns except the first. The code for that is not that flexible as the other idea, but hopefully more reliable:

    "aoColumnDefs": [ { "bSearchable": false, "aTargets": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ] } ]

    Regards,
    Tobias

    Thread Starter jptoews

    (@jptoews)

    Brilliant! Yes, that produced exactly the behavior I was hoping for. Thanks very much, Tobias.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    awesome! That’s great to hear! Thanks a lot for the confirmation!

    Best wishes,
    Tobias

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search a single column’ is closed to new replies.