How to put row number in a column to the grid conrol

Posted by ithrees on 11-Dec-2015 06:11

Hi All, 

How we can add a column in a grid control to denote the row number of each rows so that row can be easily located?

Thanks in advance,
Ithrees

Posted by jsniemi79 on 14-Dec-2015 10:28

Add a field to the object in your grid for your row number.  Then on the new and edit pages, add the following function in a script component.

<script>

 function setRowNumber(rowIndex, gridNo) {

 var displayRow = rowIndex+1;

 rbf_setGridValue2(gridNo, "Row_Number", rowIndex, displayRow);

}

 </script>

On the create and update events in the grid control, call the function and pass in the placeholders for the current grid and row number.

Lastly, you may want to add this code to the onload of the edit page if you expect the values in the grid to be resorted from the original order.  This will fire the update event on all rows and update the row numbers appropriately based on current sorting.

$("[name*='Row_Number']").change();

I hope this helps.

All Replies

Posted by jsniemi79 on 11-Dec-2015 07:50

I've done this before by using the on create event of the grid control to pass the grid row to a function.  If you do that and add 1 inside the function you call you can update the field as each row is created.  

Posted by Thierry Ciot on 11-Dec-2015 15:22
Would you expect the row numbering to be identical across sorting or various filtering operations or it does not matter?
 
Thierry.
 
Posted by ithrees on 13-Dec-2015 22:13

Thank you jsniemi79 and Thierry.

Any error messages that occurs in any record in the grid control is displayed at the bottom of the grid control stating the row numbers. As I am dealing with many number of records in the grid control its hard to locate the record with error quickly or in other word I can say that I have to count the rows to locate it.

So what I want to do is to display the row numbers which the error messages use to denote the row in the grid to ease the use of the system.

Thanks and Regards,

Ithrees

Posted by jsniemi79 on 14-Dec-2015 10:28

Add a field to the object in your grid for your row number.  Then on the new and edit pages, add the following function in a script component.

<script>

 function setRowNumber(rowIndex, gridNo) {

 var displayRow = rowIndex+1;

 rbf_setGridValue2(gridNo, "Row_Number", rowIndex, displayRow);

}

 </script>

On the create and update events in the grid control, call the function and pass in the placeholders for the current grid and row number.

Lastly, you may want to add this code to the onload of the edit page if you expect the values in the grid to be resorted from the original order.  This will fire the update event on all rows and update the row numbers appropriately based on current sorting.

$("[name*='Row_Number']").change();

I hope this helps.

Posted by ithrees on 21-Dec-2015 05:26

Thank you jsniemi79, it helped me.

What I did additionally is to style the input 'Row_Number" in order to looks like just a number label using this class,

<style>
  input[name^="Row_Number_"] {
    border: none;
    width: 22px;
    text-align: right;
    box-shadow: none !important;
}
</style>

Another thing happened after putting the onload script '$("[name*='Row_Number']").change();' the growl error message didn't stay any longer when there is an error, so I used this script inside a 'setTimeout' function to display the error message for about 2 seconds.

Thanks and Best Regards,
Ithrees

Posted by jsniemi79 on 21-Dec-2015 13:13

Great!  I'm glad it helped.

Posted by Thierry Ciot on 15-Mar-2016 14:18

By the way, you can add an Auto Number field to your object definition.

documentation.progress.com/.../index.html

Thierry

Posted by ithrees on 05-Apr-2016 23:24

Adding an auto number field won't help me here as the row numbers need to be simple as 1, 2, 3 and so on rather then a  big number sequence.

Thank you Thierry.

Ithrees

This thread is closed