Okay
  Public Ticket #1839451
Initial multi-column order
Closed

Comments

  • PrzemyslawGumulka started the conversation

    How do I set initial order based on multiple columns and allow users to manually change it afterwards? If I set it in SQL (which you don't recommend) it works fine, but I cannot allow users to change it. If I turn it on, table doesn't use order from SQL (I don't think it is properly described in documentation). There is option in each column to set it as initial order - but it works only on one column. I know how to multi-sort later manually, but how set it for initial order?

  •  2,572
    Aleksandar replied

    Hello again PrzemyslawGumulka.

    I am sorry to disappoint You, but unfortunately this is not possible with the plugin's built-in features at the moment.

    Front-end users can sort by two columns, but only if they hold down SHIFT when they sort, but sorting the table by two columns on page load is simply not possible, other than what You have already described.

    I apologize for any inconvenience this may cause.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • PrzemyslawGumulka replied

    Why just not use ORDER BY used in SQL? And then user can change the order, if we allowed it? I am not sure why turning on the possibility to change the order by user manually destroys the order set in sql. Everything works fine until I set the possibility to change order on. Was this behavior premeditated, is this a necessity? Are you planning to change it?

    One more thing: how is it working exactly at this moment, could You please describe it? What is the initial order, if neither column is set as "initial order"? I am getting weird test results and would like to know exactly how this is suppose to work. It is not described in documentation.

  •  2,572
    Aleksandar replied

    Hello again PrzemyslawGumulka.

    Please note some this when working with the server-side processing feature:

    • Please do not use “LIMIT” in the SELECT statement. wpDataTables adds it automatically and it will be overridden.
    • Please do not use “ORDER BY” in the SELECT statement. wpDataTables has its own sorting engine so it makes no sense to use MySQL’s sorting, since it will be overridden. Also, server-side processing feature adds this part of statement automatically when users trigger the sorting on the front-end, and having it in initial statement may cause the table to crash.

    This is the default behavior of wpDataTables.

    As for sorting, that depends on the way the table was created. If You have a manual table, it'll sort the table in the order You've added the data. For example, the first row with 4 columns has data B, B, B, B and the second row has data A, A, A, A. It'll be shown just like that, because of the order the rows have been added in. For tables created by linking to an existing source, the tables should load by the first column by default.

    You can add this code on page where your table is located:

    <script>
    jQuery(function(){
        jQuery(document).ready(function(){
            wpDataTables.table_1.fnSettings().aoColumns[0].bSortable = false;
            wpDataTables.table_1.fnSettings().aoColumns[2].bSortable = false;
        });
    });
    </script>
    

    Just change the numbers in aoColumns[0] by your needs. Number 0 is first column, 1 is second and so on... Maybe this will help You achieve column sorting in the way You'd like.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • PrzemyslawGumulka replied

    Hmm, my test results where different. If none of the columns is set as default and I permit users to sort for example on the 4th and 5th columns, the table will be sorted on the 4th. Only when I disable possibility to sort manually (or add it to 1st column), it will be sorted on the 1st. This was really confusing to me, all of the initial order options were somehow connected to different manual sorting options. And I think they shouldn't be connected at all. I will manage on my own so forth, thank you.

  •  2,572
    Aleksandar replied

    Hello again PrzemyslawGumulka.

    You're correct - If You disable manual sorting, the tables sort by the first column. I saw that You have only SQL columns, and that is the default behavior for tables created by being linked to an existing data source. Only manual tables don't have default sorting and the results are being displayed in the order the rows have been added.

    If You want users to sort by two columns, You can take a look at our documenatation. Also, You might want to read about Powerful Filters addon. It may have some useful tools for custom filtering.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables