How to put row number in a column to the grid conrol - Forum - Rollbase - Progress Community

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

 Forum

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

This question is answered

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

Verified Answer
  • 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
  • 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.  

  • Would you expect the row numbering to be identical across sorting or various filtering operations or it does not matter?
     
    Thierry.
     
  • 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

  • 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.

  • 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

  • Great!  I'm glad it helped.

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

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

    Thierry

  • 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