Okay
  Public Ticket #3213231
wpDataTables sorting functionality
Closed

Comments

  • Russ Loucks started the conversation

    I have a Google spreadsheet  that has about 20 columns on it.

    I display about 15 of those on a Wordpress site using wpDataTables.

    The spreadsheet is for the results of an event that takes place over a couple of days and I'll be updating often during that timeframe.

    On the Wordpress site, I would like to display the data but in a very specific sort order - sorting on about 10 of the columns.

    I know users can do a 'shift-select' and do their own sorting, but trying to do that on a tablet or phone is tough.

    Is there a way I can present the data table pre-sorted with the conditions I choose?

    I tried setting a 'filter view' on the Google spreadsheet with multiple column sorting, but that doesn't come through from the Google spreadsheet into wpDataTables.

    Thanks.

  •  1,850
    Miloš replied

    Hi, Russ 

    Sorry for the delayed answer.

    -

    Yes, on the front-end side, as you pointed out,

    the only way you can sort the table by multiple columns with plugin's built-in functionality would be if you hold down SHIFT and click on the header of 2(or more) columns.

    And correct, this means that, after the table loads, a page visitor has to do this.


    But, in case you need this to be "pre-sorted before the page loads", there is a custom workaround, with an SQL Query;

    we are not suggesting to use ORDER BY at all in queries, because wpDataTables plugin is adding it dynamically based on what is set to be default sorting column,

    but if you disable the Sorting option for wpDataTable in the table's settings,

    and create wpDataTable from SQL query e.g:

    SELECT * FROM `my_table` ORDER BY ColumnB ASC, ColumnC ASC

    It will create and show wpDataTable with multi-column sorting, but you will not be able to use Sorting anymore for this table from within the plugin's table settings.

    I hope that makes sense, let me know if that can work for your use-case.

    Thank you

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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

  • Russ Loucks replied

    Thanks for the response.

    Is it possible to create a SQL-based wpDataTable on an active Google spreadsheet?  I know I can import a Google spreadsheet into a wpDataTable.  But I would like to keep the data update flexibility of the Google worksheet.

    Thanks again.

  •  1,850
    Miloš replied

    Hi, Russ 

    You're welcome, i am happy to helpsmile.png

    - Regarding the second question,

    no, unfortunately, that is not possible.

    When working with Google Spreadsheets, if you link the source Sheet with a table,  in that case, any editing you do on the source Sheet will reflect the output table,

    but then when you use this method,  it will not be editable on WordPress and we can't pull an easy SQL Query from it.

    It will not create a new individual table in your database ( such as imported for Manual table),

    and this table won't have its own set of columns and rows,

    but their data is stored in database table wp_wpdatatables_rows. 

    So, pulling this kind of data from the database is a bit more complex because this database table stores data in JSON format, you can't  make an easy SQL Query to pull data, such as from Manual Tables ( for them you can just go like "SELECT * FROM ManualTableName")

    -

    So, you would have to choose, either to link the table to source Sheet,

    or to import it to make a Manual Table - then you will be able to pull an easy SQL Query table from that Manual Table.

    We can't have both functionalities at the same time.

    Let me know if that makes sense and if you have any questions.smile.pngThank you

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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

  • Russ Loucks replied

    I have to choose?  Oh, no!

    Actually, I think I resolved this quite nicely.  I'll let you advertise this solution.... Do I get credit for it?  ;)

    1. In my Google spreadsheet, I have a Raw worksheet and a Sorted worksheet.  I update the Raw worksheet.
    2. The Sorted worksheet includes a 'SORT()' function in A2.  Row 1 contains the headers.
    3. The SORT function in A2 looks like: =SORT("Raw!A2:U186", <col#>, <isAscending>, <col#>, <isAscending>...)
    4. In wpDataTables, I use the URL for the Sort worksheet.
    5. The tables are displayed nicely and I left sorting on for a number of columns on the front-end.
    6. If users do, indeed, sort by some column, they can just refresh the page and it returns to the 'default' sort.

    Here's a URL to the page: https://arrowheadultra.com/2023-results/

  •  1,850
    Miloš replied

    Hi, Russ 

    I apologise for the waiting time,

    and it seems that i did not initially understand your use-case correctly,  

    i thought that you needed to have an SQL based Table from a Google Spreadsheet, but it seems you needed a solution for custom sorting on the table on multiple columns.

    -

    With the current built-in capabilities of our plugin, this is the logic and a workaround we have for sorting:

    Each column has a “Default sorting column” switch. If you enable this switch for one of the columns, a selectbox will appear with options – “Ascending” and “Descending”, where you can choose the sorting direction . More about sorting with our plugin features you can read in our docs here - https://wpdatatables.com/documentation/table-features/sorting/

    2. - The only way how we can sort the table by multiple columns with plugin's built-in functionality would be, on the front-end, if you hold down SHIFT and click on the header of 2(or more) columns. ( in your case column B, then C)

    Basically, this means that, after the table loads, a page visitor has to do this, 

    click on the C column whilst holding SHIFT(added the clicked column as a secondary, tertiary etc ordering column)."

    But, in case you need this to be "already done before the page loads", there is a custom workaround, with an SQL Query;

    we are not suggesting to use ORDER BY at all in queries, because wpDataTables plugin is adding it dynamically based on what is set to be default sorting column.

    but if you disable the Sorting option for wpDataTable and create wpDataTable from SQL query e.g:

    SELECT * FROM `my_table` ORDER BY ColumnB ASC, ColumnC ASC

    It will create and show wpDataTable with multi column sorting, but you will not be able to use Sorting anymore for this table.

    -

    That was just the general information of how we usually have to use the sorting on our tables,

    but i see that you obviously made a workaround with sorting directly from the Google Spreadsheet source.

    Thank you very much for sharing your workaround solution for this type of sorting.smile.png

    We will pass this to our 2nd level Team and to our developers,  they will check it out and i believe it will help to improve our plugin in the future.

    At the moment, when you use a Google Spreadsheet with formulas, the safest option is to make a new tab with an "importrange" function as explained on our Documentation here,

    but it seems that you found a perfect solution for your use-case, so , as the saying goes "If it ain't broken, don't fix it".smile.png

    I am happy to see that you managed this solution, of course.

    Thanks again, and please don't hesitate to reach out to us with new tickets if you have any new questions, and we will be happy to assist or advise.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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