Copy link to clipboard
Copied
Hi, thanks for looking at my question. Simple question probably. How do I can I get index of the selected row in an html cfgrid. I have a button which calls startEditing(...), but how do I get the index of the selected row? Also, how do I get the row count?
Thanks for your help.
Copy link to clipboard
Copied
Although it seems like there should be an easier way to do this, here's what I came up with.
<cfinput type="button"
name="btnEdit"
value="Edit Line"
onClick="editLine();" />
...
<script type="text/javascript">
function getSelectedIndex(grid)
{
for (var i=0; i < grid.dataSource.data.items.length; i++)
if (grid.getSelectionModel().isSelected(i))
return i;
}
function editLine()
{
var grid = ColdFusion.Grid.getGridObject('gvExhibLines');
grid.startEditing(getSelectedIndex(grid), 1);
}
</script>
Still, if there is an easier or more elegant way of accomplishing the same, I would love some feedback. I'm curious why there isn't a simple grid.selectedIndex.
Also, this line:
grid.dataSource.data.items.length
returns 15 (which is my grids page size) regardless of how many rows there are in my grid.