Hey there, Awesome Customers!

Just a heads up: We'll be taking a breather to celebrate International Workers' Day (May 1st and 2nd - Wednesday and Thursday) and Orthodox Easter from Good Friday (May 3rd) through Easter Monday (May 6th). So, from May 1st to May 6th, our team will be off enjoying some well-deserved downtime.

During this time, our customer support will be running on a smaller crew, but don't worry! We'll still be around to help with any urgent matters, though it might take us a bit longer than usual to get back to you.

We'll be back in action at full throttle on May 7th (Tuesday), ready to tackle your questions and requests with gusto!

In the meantime, you can explore our documentation for Amelia and wpDataTables. You'll find loads of helpful resources, including articles and handy video tutorials on YouTube (Amelia's YouTube Channel and wpDataTables' YouTube Channel). These gems might just have the answers you're looking for while we're kicking back.

Thanks a bunch for your understanding and support!

Catch you on the flip side!

Warm regards,

TMS

Okay
  Public Ticket #3171246
Auto-Increment Column
Closed

Comments

  • Ross started the conversation

    Hello,

    I'm trying to create scoreboards, using wpDataTables, from a SQL database table.

    Is there a way to add an auto-incrementing integer column for rankings? I was hoping to have the table default sort by Score total descending, (which puts the person with highest Score at the top), then have a column showing Rank, ie 1, 2, 3, 4, 5... etc, in ascending order, based on sorting order.

    When creating a table from a SQL query I can't see any way to acheive this. Do you have any ideas?

    Thanks for your help!

    Ross


  •  1,694
    Miloš replied


    Hi, Ross 

    Thanks for reaching out to us

    -

    I have a custom workaround with a bit of JS script added to any, or all WordPress pages, and this will check if there is a table on the page, and if there is - it will add the row numbers, fixed from 1 > until the last row.

    If you change the sorting, filtering, that first column will always have fixed numbers ( Starting from 1).

    The front-end (JS) part of wpDataTables plays a significant role in the plugin’s functionality. Generally, front-end rendering is done by the DataTables jQuery plugin

    All wpDataTables existing on the page are reflected in the global JavaScript object called ‘wpDataTables‘. If you check this variable in the JS developer console you will see the wpDataTables as properties of this object. 

    What you can do is add one column in your file or data source at the start of the table (as first column), then use this script on the page ( this will work for every "first table on the page", so, for example, if you have multiple, you have to add another script, and change this bit "wpDataTables.table_1.api " to 

    " wpDataTables.table_2.api ", for the second table on same page, and so on... :

    <script type="text/javascript">
    jQuery(window).on('load',function(){  wpDataTables.table_1.api().on( 'order.dt search.dt', function ( e, dt, type, indexes ) {      wpDataTables.table_1.api().column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {         cell.innerHTML = i+1;       } );   } ).draw(); });
    </script>
    

    -

    This is just going to render on the front-end,  it will show as empty column at the back-end.

    If you need help adding custom JS to WP pages, check this article.

    Here is an example i made with a dummy table :

    I used this easy plugin that is shown on that article, Insert Headers and Footers plugin,

    and i inserted this script to entire WordPress :

    2705320248.png

    also, i added a first column to a table, with empty rows, set it as integer type :

    9011743646.png

    And this is how the table outputs on front end :

    7021475381.png

    That is without any sorting/filtering applied.

    4566423281.png

    and now i revert the sorting on the "Countries" column, but as you can see - the first column stays with the "fixed row numbers" on the front page.

    -

    Let me know if this will work for you as a solution, and if you have any further questions.smile.png Thanks

    Kind Regards, 

    Miloš Jovanović
    [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

  • Ross replied

    Thanks for the reply, Miloš

    I appreciate the suggestion but it's not going to work for me. This method would mean losing all sorting and search functionality, which is half the point of using wpDataTables in the first place.

    I guess I was just making a naive assumption that wpDataTables would have a built in method to generate a numerical order column based on the default sorting column results. If someone can't search their name in the table and see their numerical position then it's no good as a leaderboard.

    I'll have to request a refund and have a custom plugin made.

    Thank you for your efforts.


  • Ross replied

    Additional notes for anyone attempting the suggested solution.

    You cannot create a wpDataTable with an empty column in the 0 position (far left). You will get an error. To solve this bug you'll have to create the table with the empty column on the far right of your table (selected last from your SQL columns), then move it back to the 0 position while editing the tables appearance.

    The empty column only propogates with numbers for me while previewing the page using Elementor. When viewing the actual published page the column remains empty.

  • Ross replied

    I realise that what I want is quite specific to scoreboards or leaderboards; automatically numbering each row based on the result of the sorted column, but I'm very surprised there isn't an option to include at least a static numeric column.

    If there were I might consider not using any of the filter / sort / search capabilities of wpDataTables and just settle for a static table. The jQuery workaround is just janky though, and not working reliably for me.

  •  1,694
    Miloš replied

    Hi, Ross 

    I can completely understand where you're coming from, and that you need this specific solution for your use-case,

    but unfortunately, the custom workaround with JS is the only one we have for the time being in terms of making a "fixed row number column", that will not be affected by sorting/filtering.

    We did have a couple of other users with a similar use-case, so we have this in scope for the future to add better solutions,

    i just can't promise any ETA on that at this time.

    You can suggest it for our developers - they will do their best to make a solution in the future.

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    If you need a solution for it now, maybe it can be done with a high level of custom work, but I am not sure, to be honest. Our developers are very busy at the moment, working on some priority tasks and fixing bugs and issues with our plugins, so they won't be having the time for custom work in the near future.

    We can recommend reaching out to someone who does custom solutions, such as WP Kraken, but we can't advise on their pricing.

    -

    I do realise that you asked for a refund, on the other ticket, we will respond to that now,

    you will get a full refund, of course, 

    but in case if any of this helps, just wanted to share the information.

    Thank you

    Kind Regards, 

    Miloš Jovanović
    [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