on 2018 Dec 17 8:33 PM
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
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
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);
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
Try getting the rowcount after the page has completed loading as Christian suggested.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'
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
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.