WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Second Sorting Criteria (11 posts)

  1. ihlonline
    Member
    Posted 9 months ago #

    Me again,

    it is still working fine, no worries.

    But can I add a second criteria to sort my rows? So for example (I am dealing with sport standings) when two teams have the same amount of points, that the second criteria would be the goal difference. Is that possible?

    Thanks heaps and regards from Sydney

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

  2. ihlonline
    Member
    Posted 9 months ago #

    EDIT: My used code at the moment is:
    [table id=wes filter="blackhawks||avalanche||dallas stars||minnesota wild||nashville predators||st. louis blues||winnipeg jets" hide_columns="1" row_order="sort" row_order_sort_column="J" row_order_sort_direction="DESC"/][/tab]

  3. Haoxian
    Member
    Posted 9 months ago #

    Hi,

    Maybe you could achieve this by using aDataSort command.

    Let's assume that your score column is the 1st column, and goal column is the 2nd, then the multicolumn sort aDataSort command is like the following:

    "aoColumnDefs": [
          { "aDataSort": [ 0, 1 ], "aTargets": [ 0 ] }
        ]

    Just add this command to cusome command field in "Feature of DataTables JavaScript Library" section when editting the table in TablePress admin page.

    Please confirm by replying whether this works for you.

    Regards,
    Haoxian

  4. Haoxian
    Member
    Posted 9 months ago #

    And further, if you also want a combination sort for it when clicking on the 2nd column head, the custom command should be changed to:

    "aoColumnDefs": [
          { "aDataSort": [ 0, 1 ], "aTargets": [ 0 ] },
          { "aDataSort": [ 1, 0 ], "aTargets": [ 1 ] }
        ]
  5. ihlonline
    Member
    Posted 9 months ago #

    Hey,

    sounds difficult. Where should I enter the code?? Because I am not talking about a table. As you can see in my above post I use a code, to exclude certain teams of my large table.

    For example: Eastern Conference hosts 16 teams, just 8 of them should be displayed in my table. Everything worked fine, I got that table. And the table is sorted by points, perfect. But know: Where to put the code? In my above posted code?

    But thank you for your help so far.

    EDIT: First sorting priority: Points (10th column)
    Second sorting priority: Goals difference (9th column)

  6. Haoxian
    Member
    Posted 9 months ago #

    Well then, the command should change to:

    "aoColumnDefs": [
          { "aDataSort": [ 9, 8 ], "aTargets": [ 9 ] },
          { "aDataSort": [ 9, 8 ], "aTargets": [ 8 ] }
        ]

    In your WP Dashboard, navigate to TablePress, then choose to Edit this particular table. At the edit screen, scrolling down to section with title "Feature of DataTables JavaScript Library", there should be a line of text
    field at the last line in this section. Just put the code into it and save.

    Then go to view your page to see if this is what you expect.

  7. ihlonline
    Member
    Posted 9 months ago #

    Okay! Unfortunately it doesnt work :(

    But thanks :)

  8. Haoxian
    Member
    Posted 9 months ago #

    Sorry for that. Please wait for the author to solve it.

  9. TobiasBg
    Member
    Plugin Author

    Posted 9 months ago #

    Hi,

    thanks for your post, and sorry for the trouble.

    Unfortunately, the Table Row Order Extension can only use one sort criterion, so the only chance here is to use the JS based sorting.

    Instead of the aDataSort parameter, we'll however need the aaSorting, which defines the initial sort that shall be performed.
    Also, the numbers in the JS code (for the columns) only take into account the visible columns on the page, and as one column is hidden in the table, the 8 and 9 become 7 and 8 (but in reversed order, so that PTS is sorted on first). So, please try this "Custom Command":

    "aaSorting": [[8,'desc'], [7,'desc']]

    Regards,
    Tobias

  10. ihlonline
    Member
    Posted 9 months ago #

    You made it! Awesome.

    Thanks mate!

  11. TobiasBg
    Member
    Plugin Author

    Posted 9 months ago #

    Hi,

    no problem, you are very welcome! :-) Good to hear that this helped!

    Best wishes,
    Tobias

Reply

You must log in to post.

About this Plugin

About this Topic