Add a Row Number into a Wix Table

Hi all,

I’ve spent multiple hours trying to get this to work but I’m struggling.

I have a collection called “Standings” that contains various players, scores, total points etc. This is linked to a table on my site that is controlled by multiple drop down boxes to view historical scores.

I have that part working, but what I’d like to have is an automatic row numbering system that adds a 1,2,3,4 etc onto the table for the persons current position within the standings. This could be 1-6, or 1-12 etc, dependant on the amount of rows returned on the data selected.

I have added a blank column at the start of my table via:

let cols = $w ( “#table2” ). columns ;
cols . unshift ({
“id” : “rownumber” ,
“dataPath” : “rowNumber” ,
“label” : “#” ,
“width” : 40 ,
“visible” : true ,
“type” : “string”
});

$w ( “#table2” ). columns = cols ;

However I cannot seem to get the numbering system to work despite trying many things!

Please could anyone assist?

Thanks,

You can easily do that just adding this rowNumber column that you created as a property to each object in the array that feeds the data to your table.

data.forEach((element, index) => {
    element.rowNumber = index + 1
})
$w("#table").rows = data