I have a grid control filled with data in 4 columns. How do I get the row index of the area of the grid that is clicked?
I may have missed this solution in a sample but I did not find one.
Ryan
I have a grid control filled with data in 4 columns. How do I get the row index of the area of the grid that is clicked?
I may have missed this solution in a sample but I did not find one.
Ryan
Have a look at the Wiki:
https://wiki.appstudio.dev/Grid
Code for doing this in both JavaScript and BASIC is included.
The GridWithScrolling sample also shows how to do this.
I have this grid click event:
gridCrews.onclick=function(event){
alert('grid click');
//need to get position to get index of row in table for id
var s = Split(event.target.id, "_");
var row = s[1];
alert(row);
alert("Click on " + s[0] + " at row " + s[1] + " and column " + s[2]);
alert("Value is " + gridCrews.getValue(s[1] ,s[2]));
}
I get the first alert, but I get no other feedback from this code.
Ryan
The correct way to do this is:
gridCrews.onclick=function(event){
//need to get position to get index of row in table for id
var str = event.target.id;
var s = str.split("_");
var row = s[1];
}
I was trying to use the BASIC version of split
Hi ryansy,
I tried this code and it didn’t work?? Has it been updated?
Thanks…Joel
Can you be more specific than “it didn’t work??”?
Joel, this is what I ended up using:
gridCrews.onclick=function(event){
var str = event.target.id;
//gives me 'control name'_'row'_''column'
var s = str.split("_");
var row = s[1];
if (row == 0)
{
return;
}
else
{
row = row -1;
}
Hi Ryan,
Thanks for your response. I tried your code and it is returning an HTMLDivElement object as the
event.target.id. However, the str.split is only returning the control name in s[0]. s[1] (row) and s[2]
(column) are undefined. Is there a setting I should be using in the control grid properties or am I
missing something else concerning the split? I appreciate your assistance. Thank you…Joel
The code returns a HTMLDevElement object, but the Split does not return the row or column. s[0] contains the control id. Is there setting in the grid properties to enable the correct split? Also, I had
to use event.currentTarget.id. Thanks for any assistance…Joel
Hi Ryan,
I got your code to work successfully. I was using the wrong grid. I switched from the jqwgrid
to the common grid. Thanks for your help…Joel
You bet. Glad it worked.
I got Ryan’s code to work successfully. I was using the wrong grid. I switched from the jqwgrid
to the common grid. Is there a similar code example for the jqwgrid? Thanks for your help…Joel