Title: Sorting function with images?
Last modified: August 30, 2016

---

# Sorting function with images?

 *  Resolved [moliver27](https://wordpress.org/support/users/moliver27/)
 * (@moliver27)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/)
 * This is a great plug-in Tobias! The company I work for created a table to include
   contact information for distributors which includes a column that contains company
   logos. You can view the table here: [http://www.willburt.com/contact-will-burt/international-distributors/](http://www.willburt.com/contact-will-burt/international-distributors/).
   I recently eliminated the custom sorting code because the dropdown menu isn’t
   working. I’m wondering if this is because the images cannot be sorted or if there
   are additional settings that I need to review. Thanks!
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735426)
 * Hi,
 * thanks for your question, and sorry for the trouble.
 * Yes, indeed, images can not really be sorted. The JS can obviously not “see” 
   what’s shown on them 🙂 (Technically, the sorting could use the image name, but
   that would not really be reliable.)
 * In your case, I’d therefore suggest that we instruct the sorting function to 
   use the company name (from the first column) as the data that is used for sorting,
   when the user tries sorting the logo column. That should make the most sense.
   
   For that, please turn on the sorting again and add this to the “Custom Commands”
   text field on the “Edit” screen of the table:
 *     ```
       "columnDefs": [ { "orderData": [ 0 ], "targets": [ 5 ] } ]
       ```
   
 * (as counting the columns starts with 0, the first column (name) has the number
   0, while the sixth column (logo) has the number 5).
 * Regards,
    Tobias
 *  Thread Starter [moliver27](https://wordpress.org/support/users/moliver27/)
 * (@moliver27)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735443)
 * Thanks for the prompt reply Tobias. Let me rephrase the question because I only
   want to sort (2) individual columns. In this particular table, I only want to
   sort by “Company Name” and “Country” which are columns 1 and 3, respectively.
   I don’t want to sort by the column that displays the image. However, I can’t 
   seem to get the sorting function to work at all and I think it’s because of the
   images. Does that make sense? Thanks Tobias!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735455)
 * Hi,
 * ah, ok. In that case, please use this “Custom Command”:
 *     ```
       "columnDefs": [ { "orderable": false, "targets": [ 1, 3, 4, 5, 6, 7 ] } ]
       ```
   
 * For this to have an effect, you must however turn on the “Sorting” checkbox on
   the “Edit” screen as well.
 * Regards,
    Tobias
 *  Thread Starter [moliver27](https://wordpress.org/support/users/moliver27/)
 * (@moliver27)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735470)
 * Thanks Tobias. This may take a little tinkering to work properly. Am I able to
   use the “Fixed Header” extension along with the sorting function for this to 
   work?
 * Here is the code I have in place when I edit the specific page the table is placed:[
   table id=57 datatables_columnfilterwidgets=true datatables_columnfilterwidgets_exclude_columns
   =2,4,5,6,7,8 / datatables_fixedheader=”top” /]
 * Here is the code of the edit table in tablepress: “columnDefs”: [ { “orderable”:
   false, “targets”: [1, 3, 4, 5, 6, 7 ] } ]
 * Notice how the columns have different numbers because the edit table starts with“
   0”. Should I match them?
 * I hope this makes sense Tobias. Thanks for all of your help and support!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735478)
 * Hi,
 * this looks all correct. In the Shortcode, the regular numbers (starting at 1)
   are used. In the “Custom Commands” they start with 0, as that’s JavaScript code.
 * Regards,
    Tobias
 *  Thread Starter [moliver27](https://wordpress.org/support/users/moliver27/)
 * (@moliver27)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735486)
 * Huh, well I wonder what the problem is. I inserted the custom command code and
   enabled the sorting function within the table. However, nothing gets filtered
   when a select a specific dropdown. [http://www.willburt.com/contact-will-burt/international-distributors/](http://www.willburt.com/contact-will-burt/international-distributors/)
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735601)
 * Hi,
 * ah, now I see. You are talking about the ColumnFilterWidgets, which have nothing
   to do with sorting. That confused me a bit here 🙂
    For those to work, you will
   also have to turn on the Search/Filter checkbox. If you then don’t want to actually
   show the search field, you can hide it e.g. with “Custom CSS” like
 *     ```
       #tablepress-57_filter {
         display: none;
       }
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [moliver27](https://wordpress.org/support/users/moliver27/)
 * (@moliver27)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735691)
 * Thank you Tobias that worked great!! Do you by chance know of a reference area
   with the different custom commands and what they do? such as: “columnDefs”: [{“
   orderable”: false, “targets”: [ 1, 3, 4, 5, 6, 7 ] } ].
 * Thanks!!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735692)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * Yes, all those “Custom Commands” basically come from the DataTables JS library,
   see [https://www.datatables.net/reference/option/](https://www.datatables.net/reference/option/)
 * Best wishes,
    Tobias

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Sorting function with images?’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [custom sorting](https://wordpress.org/support/topic-tag/custom-sorting/)
 * [dropdown](https://wordpress.org/support/topic-tag/dropdown/)
 * [images](https://wordpress.org/support/topic-tag/images/)

 * 9 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/sorting-function-with-images/#post-6735692)
 * Status: resolved