Support » Plugin: TablePress » Sort Extension – Sort by Month Name

  • Resolved benchwarmer

    (@benchwarmer)


    Hi Tobias,

    Thanks for putting in your time to make this plugin. It’s so clean it’s a pleasure to use. Thanks also for the Responsive Extension. I downloaded it and yes I did donate!

    I also installed the extension for sorting, and I was wondering–as I can’t seem to find reference to it in documentation–if it’s possible to sort by Month Name only, e.g. January, February, March, etc. I have a date field that is a “Look ahead calendar” where I’m giving ballpark dates for events, and don’t want to be specific as to month/year if I don’t have to since the month is the same every year going forward. However the sort appears to not recognize Month names, and just sorts alphabetically. Hoping that’s a possibility. If not, I’ll revert to number values like 1/19, 2/19 which I assume are identified.

    Thanks!

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Directly sorting the month names is not possible, as the sorting algorithm “can’t read” the meaning of the words, so to say.
    You could however use an approach that makes it possible to basically sort any data: You would add an extra column that is hidden to the visitor, but that contains numerical information that the sorting algorithm can use for the sorting of the actual column.
    For examples, with very similar tasks, please see https://wordpress.org/support/topic/sort-rows-by-date-with-a-hidden-column/ and https://wordpress.org/support/topic/sort-with-pictures-alt-tag/

    Regards,
    Tobias

    Thread Starter benchwarmer

    (@benchwarmer)

    Thanks. If I understand the method you’re proposing, I’d have to create a hidden column that basically parallels the “real” column so that if the latter says “January” the hidden column would say “1” and go forward like that, so that every corresponding cell with “January” in it would have a cell in the hidden column as “1” and so on through the 12 months. I think that solution is a little too clunky for my use case. I was looking for a more relational solution where each month string is assigned a variable value to sort by.

    I looked at datatables.net. Seems like this question was posed there and someone worked out a way to do it, I’ll just have to figure out how to incorporate into the plugin, if it can be done.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    correct, that’s what I meant. But I’m not sure why you are saying that it’s clunky. It’s just one more small column with a small number in it.

    Of course, it would be possible to directly write a sorting algorithm that understands month names. This could then be incorporated into the TablePress Extension from https://tablepress.org/extensions/datatables-sorting-plugins/ which already has other sorting algorithms in it.

    Regards,
    Tobias

    Thread Starter benchwarmer

    (@benchwarmer)

    I have two date columns for two different generic deadlines, so I need two hidden columns. That makes the solution clunky.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ok, I see. In that case, the custom algorithm might indeed be more streamlined.

    Regards,
    Tobias

    Thread Starter benchwarmer

    (@benchwarmer)

    Hi Tobias,

    Since I need to launch this website sooner than later and I’m still working out the code to do the sort dynamically I thought I’d try the solution you provided, but it doesn’t seem to work. I added a column I put the command in the Custom Commands area but instead of the expected results I get an additional visible column and the sorting function seems to be completely turned off. Any ideas?

    Thread Starter benchwarmer

    (@benchwarmer)

    OK, I was playing with this and the only way I could get it to work was to remove the quotes. That doesn’t make any sense to me as I’d expect this is injected into the function as shown here: https://datatables.net/examples/basic_init/hidden_columns.html

    So why would in my case the quotes be a problem? Also I can only seem to use one of these command lines if I try to run two together it breaks.

    Thread Starter benchwarmer

    (@benchwarmer)

    OK I finally worked it out. I wasn’t able to combine the commands in the same way you showed in the other posts. I had to break it up. One command to hide the column and a whole other command for orderData. Here’s what I mean for your (anyone else with this issue) reference:

            "columnDefs": [
                {
                    "targets": [ 4 ],
                    "visible": false,
                },
                {
                    "targets": [ 6 ],
                    "visible": false,
                },
    
               {    "orderData": [ 6 ],
                    "targets": [7],
                },
    {    "orderData": [ 4 ],
                    "targets": [5],
                },
            ]
    
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    nice, this looks good! 🙂

    Just in case: You might have to remove the extra commas after the last ] inside a {} block, and after the last }.

    Regards,
    Tobias

    Thread Starter benchwarmer

    (@benchwarmer)

    Commas didn’t interfere with the processing of the script. Still probably bad form so anyone else using the above might wish to remove them.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ok, that’s good to hear. I was just trying to make sure, as (at least) Internet Explorer can sometimes be picky with extra commas in JavaScript code.

    Regards,
    Tobias

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Sort Extension – Sort by Month Name’ is closed to new replies.