Okay
  Public Ticket #3199705
Index columns
Closed

Comments

  • Ahmed Al-Mahrooqi started the conversation

    I have a table with filters reading from an excel file, although the data source does have an index column, I would like to automatically index the column in a matter that gets updated after you filter.

    In other words, if I have a table with 100 rows, I want it to show an index column for each record. If I filter the data and only 50 rows show I would like the index column to start over from 1 to 50, instead of showing me the 50 records with indexes from 1-100. 

    I do not know how to create an index column or make it dynamic yet, which is what I'd like your help with. Thank you.

  •  1,850
    Miloš replied


    Hi, Ahmed 

    My apologies for the late response.

    We had a New Years break and are back,   will do our best to be quick with our responses going forward.

    I wish you a Happy New Year, and all the best in 2023!smile.png

    -

    If i understood you correctly,  you wish to have a column that is always going to show "fixed row numbers" regardless of the filtering and pagination of the table?

    So , the first 50 rows should always "count" from 1 to 50 , even with filtering of data.

    -

    We don't have any built-in feature to achieve this at the moment.

    If you wish to see a built-in 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.

    -


    At this time, you can only try custom solutions.

    I have a custom workaround to offer 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 tables on same page, 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