Monday, September 30, 2013

Row number on paginated af:table

A quick tip..

Usually we use #{row.index + 1} to show the row number in table component. But when we use the same in a paginated table, for every page the row number will starts with 1 because row.index starts with 0 for every page.

How to display the correct row number?

bindings.<TREE_BINDING_ID>.rangeStart will give the corresponding page range start value. For eg if the page size is 10 and if you are in 4th page then rangeStart value will be 40.

So adding this rangeStart with row.index will display proper row number:

#{row.index + 1 + bindings.< TREE_BINDING_ID>.rangeStart}

Eg: #{row.index + 1 + bindings.EmpVO.rangeStart}

Here 'row' refers to af:table 'var' property value.

and EmpVO refers to tree binding id