cancel
Showing results for 
Search instead for 
Did you mean: 

i5Grid getRowCount() is not working on page loading

0 Kudos

when the page loads am trying to get the number of rows in the i5Grid but am not sure why it shows 0 row count. The only time where I could see the row count is when the i5Grid is selected.

Below is the sample code:

var grid_c0c0 = new com.sap.xmii.grid.init.i5Grid("grid template path","query templ path",true);
grid_c0c0.registerCreationEventHandler(ceController.addObject("c0c0",grid_c0c0));
grid_c0c0.draw("gridc0c0");
alert("initial"+grid_c0c0.getGridObject().getRowCount());

I couldn't figure out what is the issue. Any help would be Appreciated.

Thanks

Sap

agentry_src
Active Contributor

Please change your "Answer" to a comment to a specific Answer provided. One is unable to follow the chain of responses when you provide an additional answer rather than a comment to a specific solution provided. Pick the answer you are responding to and make a comment which is then specific to the Answer provided.

Regards, Mike

Accepted Solutions (1)

Accepted Solutions (1)

This property actually worked for me and I could get the rowcount even before the page loads. I wrapped the draw call as suggested by Christian but used a different property. This way I can even color the records based on my conditions.

var i5Grid_Applet = new com.sap.xmii.grid.init.i5Grid("Test/gridEmails_Html","Test/getEmailList");
i5Grid_Applet.setGridWidth("640px");
i5Grid_Applet.setGridHeight("400px");
$.when(i5Grid_Applet.draw("myDiv")).done(function(){
var count =i5Grid_Applet.getOriginalRows().length;
alert(count);
});

Answers (3)

Answers (3)

former_member185280
Active Contributor

I guess there is some race condition going on in the bowels of the objects. FWIW it only seems to be happening with the first update event. the regular update event doesn't seem to have the issue.

On a hunch I wrapped the draw call in a promise and it seems to be working.

$.when(i5Grid_Applet.draw("myDiv")).done(function(){  
  var count = i5Grid_Applet.getGridObject().getRowCount();
  alert(count);
});
0 Kudos

I tried the same but it doesn't seem to be working for me . Still getting 0 as row count.

Should I change anything in i5grid in specific?

former_member185280
Active Contributor

I think some async goes on and you may be trying to use parts of the grid object before they get completely instantiated. Try triggering your logic with the FirstUpdate or Update events. There won't be any rows or data in there anyway until those are fired.

0 Kudos

Here is the code sample which I tried with first update event and I still get the same error. Am not sure if anything is wrong with my code.

<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Test Page---</TITLE>
<META http-equiv="X-UA-Compatible" content="IE=edge">
<META HTTP-EQUIV='Expires' CONTENT='-0'>
<meta http-equiv='pragma' content='no-cache'>
<SCRIPT type="text/javascript" src="/XMII/JavaScript/bootstrap.js" data-libs="i5Chart,i5Grid">
</SCRIPT>
</head>
<SCRIPT type="text/javascript">
function checkValue(){
var count = i5Grid_Applet.getGridObject().getRowCount();
alert(count);
}

var i5Grid_Applet = new com.sap.xmii.grid.init.i5Grid("Test/test_i5grid","Test/test_qry15");
i5Grid_Applet.setGridWidth("640px");
i5Grid_Applet.setGridHeight("400px");
i5Grid_Applet.registerFirstUpdateEventHandler(checkValue);
i5Grid_Applet.draw("myDiv");
</script>
<body>
<div id="myDiv"></div>
</body>
</HTML>

agentry_src
Active Contributor
0 Kudos

Hi Sap Ram,

Please mark Christian's Answer as correct so others will know the solution which applied to the problem you encountered. You can also close the question after that.

Regards, Mike

agentry_src
Active Contributor
0 Kudos

Try getting the rowcount after the page has completed loading as Christian suggested.

0 Kudos

I actually need the row count before the page completes loading. I have few more requirements like changing the color of certain cells in the i5Grid based on few conditions and to use setCellValue to set some values on i5Grid based on conditions.

Anything I try using getGridObject() method doesn't work. But it seems to be working after OnSelection event .

Below is the error message which I could see in console

SCRIPT438: Object doesn't support property or method 'getRowCount'

agentry_src
Active Contributor

I don't think that will work since the object you are trying to read does not exist until after the grid is populated. So let it populate, then get your rowcount and do your updates afterwards. There are probably several other ways to hold the information before passing it to the grid, but I would recommend this approach as simpler and easier to maintain.

Regards, Mike

0 Kudos

Thanks Mike & Christian for your inputs! Am currently populating the grid and then doing my updates.