Okay
  Public Ticket #3018362
Formula or code for entry table position number (leaderboard)
Closed

Comments

  • Callum Edwards started the conversation

    Is it possible via formula or code to have a number sequence of entry position in the table. For example I have create a table which is for a leaderboard, I want a column showing 1 to 5 which is based on the order of the entries in the table, so when a new try is added if this goes to the top of that table it would become 1 and the sub entries would drop down position. 


    Hope this makes sense.

  •  1,851
    Miloš replied


    Hi, Callum

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    I've been searching for a workaround to make a solution as you need it, but despite my best efforts, still unsuccessful.

    I will escalate this with our 2nd level Team, to see if they got any workarounds. I was thinking of possibly something with custom JS that would only render on the front page, but, as I mentioned, didn't get it working yet.

    Can you tell me, just to check - do you need the column to always show that number sequence only on the front-end page, or is it also important to have it show on the back-end in the WP-Admin plugin editor?

    I will report back after more work on this. Thank you for your patience.

    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

  • Callum Edwards replied

    Hi Miloš,

    No worries! I appreciate your help. 

    You are correct I just need the sequence showing on the front page to so I can show the results in a leaderboard style the first result showing as 1st place (1)

    Thank you

  •  1,851
    Miloš replied

    Hi, Callum.

    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.

    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

    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

  • Callum Edwards replied

    Thank you, apologies if this is a silly question but if my data is being collected from a gravityform source how do I add an empty integer column? - Do I add this as a hidden empty field into the gravity form?

  •  1,851
    Miloš replied

    Hi, Callum

    That is a good question, to be honest with you, i didn't test that situation yet.

    That does sound as it should work, theoretically. If you can try to add the field as empty and hidden on the Gravity Form side , just set the field type as numeric > and then when you link it during table creation, add this column to the table, when you select all the fields from the Form - set that one as integer;

    and try the workaround i sent you.  I know that form plugins can usually have hidden fields, and wpDataTable can still load them.

    Let's see , and let me know how it goessmile.png

    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

  • Callum Edwards replied

    Hi Miloš

    That's worked for the table i've tried. I have multiple tables display on the one page however I can test the code on the additional tables as the filters aren't working correctly (i've raised a new ticket for this). I assume its going to work once I have that sorted so I appreciate all your help!

  •  1,851
    Miloš replied

    Hey, Callum

    I see the other ticket - we will proceed on it regarding filtering.

    But once you try this JS trick for other tables, to present the numbering, you can come back to this ticket if it doesn't work for any reason on other tablessmile.png

    It is good that you made a separate ticket for different topics - that makes our support more efficient, and tracking issues.

    Let's see how it goes.

    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