Get total number of records in a Grid Control

Posted by IramK on 30-Jan-2015 06:02

Hello,

I am trying to get the total number of records in a grid control and I have been able to achieve this using the rbf_getMaxRowIndex2() function. However, when I delete a grid record, it still comes back with an index which I'm sure is what is expected from that function. Is there a way I can get the total number of records available in that grid?

Posted by Gian Torralba on 05-Feb-2015 15:02

Hello,

Did the previous sample code works? If not, there is a JQuery alternative that we are using. What we do is we count the number of rows using the grid number and then the class name of the "tr" element.

//run on delete event of grid
function funcName(gridNo){
var rowCount = $("#rbi_gridTable_" gridNo " tr[id*=rbi_gridRow]").length;
}

Thank you,
Gian

All Replies

Posted by ymaisonn on 30-Jan-2015 07:21

Hi,

Try the following code:

var n =  rbf_getMaxRowIndex2(0);

var numRows = 0;

for (var rowIndex=0; rowIndex<n; rowIndex++) {

var x = rbf_getGridValue2(0, 'id', rowIndex);

 if (x !== null){ numRows++; }

}

alert ('Number of rows: ' + numRows);

You can retrieve the MaxRowIndex value then iterate from 0 to MaxRowIndex.

You verify whether a row exists for a given rowIndex value by checking whether a read-only and compulsory value is not null (such as id).

This field (read-only and compulsory) must be added to the grid. If the field value is null it means that the row referenced  by the row index does not exist. In that case you don't increment the row count counter.

Posted by IramK on 30-Jan-2015 08:30

When I try to get the Grid Value for 'id', I always get a null. So, i'm not really sure if we can get the gridValue by using an ID. Is there any other field that I could use to do this if I don't have any compulsory fields? ID seems to be a good option but it doesn't seem to work in this case.

Posted by pvorobie on 30-Jan-2015 12:10

Do you have Grid column for "id" field?

Posted by ymaisonn on 30-Jan-2015 12:47

Indeed, the candidate, read-only and compulsory, field (in the example : 'id') must be added to the grid.

Posted by Gian Torralba on 05-Feb-2015 06:41

Hello,

Can you access the ID value inside the grid now?

Thank you,
Gian

Posted by IramK on 05-Feb-2015 07:47

Yes I can access the ID value inside the grid row but I dont want to show the ID.

Posted by Gian Torralba on 05-Feb-2015 15:02

Hello,

Did the previous sample code works? If not, there is a JQuery alternative that we are using. What we do is we count the number of rows using the grid number and then the class name of the "tr" element.

//run on delete event of grid
function funcName(gridNo){
var rowCount = $("#rbi_gridTable_" gridNo " tr[id*=rbi_gridRow]").length;
}

Thank you,
Gian

This thread is closed