WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
[resolved] Removing the up/down sorting arrows on specific columns (10 posts)

  1. rawdolphe
    Member
    Posted 2 years ago #

    Hi Tobias,

    Is there a way to remove the up/down sorting arrows on specific columns, when using the DataTables? i.e, some entries don't need sorting.

    Thank you

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  2. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    yes, that is possible with some additional commands for the DataTables library.
    For example, the following code will disable sorting on the second and fourth column (counting starts at 0, that's why the numbers in the code are 1 and 3).

    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 1, 3 ] } ] } );

    Just paste this into the "Custom Commands" textfield in the "DataTables JavaScript Features" section on the "Edit" screen of the table where you want to disable sorting for some columns.

    Regards,
    Tobias

  3. rawdolphe
    Member
    Posted 2 years ago #

    Hi Tobias,

    Thank you for you help, the above code is actually removing everything, sorting, paginations, filtering etc...

    I was trying something similar earlier on, based on the thread, I lost it now!

  4. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    oh, yes, my code removes everything, because it is wrong... Sorry about that. I copied to many brackets. Please try again with this:

    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 1, 3 ] } ]

    Regards,
    Tobias

  5. rawdolphe
    Member
    Posted 2 years ago #

    Hi Tobias,

    Thank you that works great.

    However, I am also testing the other Custom Commands I came across here, and the following breaks it, so maybe I am doing something wrong:
    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 2, 3 ] } ], "bAutoWidth": false, "aoColumnDefs": [ { "sType": "currency_sorting", "aTargets": [ "column-7" ] } ], "aoColumnDefs": [ { "sType": "html", "aTargets": [ 1 ] } ]

    However, the following (shorter line) works:
    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 2, 3 ] } ], "bAutoWidth": false,

    Mind you, at this minute, I am only experimenting, just trying things out, even if I don't end up using the Custom Commands above, it's always good to know about it.
    I might sell recipes or articles and what not... will see :P The sky is the limit.

    The other question if you don't mind, say I am doing a table with recipes, 125 grams comes before 2 grams in the sorting, is there an easy way to change this?

    Thank you again

  6. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    your longer list of Custom Commands is probably not working, because you are having the same property in the code several times. You will probably have to merge the "aoColumnDefs" into one.

    Regarding the sorting: This probably happens because you are having strings in the cells, instead of just numeric values, and those are sorted differently.

    Regards,
    Tobias

  7. rawdolphe
    Member
    Posted 2 years ago #

    Ah thank you, so what should the Custom Command look like then?

    For the other issue, would you say that instead of 125 grams for example, I should use 125 (no grams), etc...?

  8. rawdolphe
    Member
    Posted 2 years ago #

    PS: I can confirm that removing the "grams" fixes the sorting/ordering issue.
    Would be good if there was a way to make it work with it though.

  9. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    probably something like

    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 2, 3 ] }, { "sType": "currency_sorting", "aTargets": [ "column-7" ] }, { "sType": "html", "aTargets": [ 1 ] } ], "bAutoWidth": false

    If you want the search with the "grams" in the cells, you will need to develop a custom sorting algorithm for the DataTables JavaScript library. This simply is a result of how sorting of data works.

    Regards,
    Tobias

  10. rawdolphe
    Member
    Posted 2 years ago #

    Hi Tobias,

    Thank you, will try this later on.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic