TIP: Displaying row numbers with the Data Grid

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

TIP: Displaying row numbers with the Data Grid

Postby steve1376656734 » Fri Aug 23, 2019 3:54 pm


I had a requirement to display row numbers when showing data in the AG data grid and I could not find a simple way to achieve it. In our old web-client solution I simply used a table view form and one of the fields displayed %%currentRecordIndex%% but with the new data grid in NG client I couldn't see how to use that without adding a calculation to the table that returned the foundset index and didn't want to do that for all my tables. Having researched it a bit on the web I came up with the following solution:

  • Add a column to the grid (I always make this the first column)
  • In the column properties click the columnDef and add three properties named lockPosition, suppressNavigable, and valueGetter
  • Expand the columnDef node and set the property values to true, true and 'node.rowIndex + 1' respectively (Servoy will add the quotation marks for you)
  • Change the showAs property to html
  • Change the width of the column to suit the number of rows you expect in the table. 50px is enough to show a 3 digit number if the font size is 12px but experiment to suit your current styling
screenshot.jpg (68.76 KiB) Viewed 389 times

Resulting output:
row_numbers.jpg (113.51 KiB) Viewed 389 times

I hope this is not a sledgehammer to crack a nut and if there is some simple way to achieve it then please feel free to update this thread.
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
Posts: 226
Joined: Fri Aug 16, 2013 2:38 pm
Location: Lanzarote

Return to Programming with Servoy

Who is online

Users browsing this forum: MSN [Bot] and 2 guests