cancel
Showing results for 
Search instead for 
Did you mean: 

How to make an auto row numbering column for table?

Former Member
0 Kudos

Hi all,

I want to add a column to a table which shows the the current row number. Is there an easy way to do it?

when i sort the table, i want the column remains the same order.

when i delete one row in middle, it automatically keep the numbering continually

is there a way?

Thanks !

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi there,

You can add a context attribute under your node.

Do this in the modifyView method


for(int i=0; i<wdContext.nodeCustomer().size(); i++) {
		IPrivateMainComponentView.ICustomerElement ele = wdContext.nodeCustomer().getCustomerElementAt(i);
		ele.setColumnNumber(i+1);
	}

This would ensure that the column number gets "recalculated" everything the view is changed.

Former Member
0 Kudos

this is really good thinking, but any performance draw back??

Former Member
0 Kudos

Why in wdDoModifyView()?

Armin

Answers (3)

Answers (3)

Former Member
0 Kudos

Add a calculated attribute "number" under the table data source "Rows". Implement it like


int getRowsNumber(IRowsElement element)
{
  return element.index() + 1;
}

Armin

Former Member
0 Kudos

Using loops does eat up the performance "TECHNICALLY" but don't think that will crash the system. It's fairly manageable.

nikhil_bose
Active Contributor
0 Kudos

i think of easy way by calling a method which sets numbering manually.


int size =  wdContext.nodeTable().size();
for(int i =0; i<size; i++) {
wdContext.nodeTable().getTableElementAt(i).setRowNum(i+1);
// Table - Node name
// RowNum - attribute in Table Node 
}

nikhil