WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Search a single column (6 posts)

  1. jptoews
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/extend/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for your question.

    I see two possibilities here:
    1.) You could use a different TablePress Extension from http://tablepress.org/extensions/datatables-column-filter/ that adds a text field for each column, as can be seen on http://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

  3. jptoews
    Member
    Posted 1 year ago #

    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:

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

  4. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    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

  5. jptoews
    Member
    Posted 1 year ago #

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

  6. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

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

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic