jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Dynamically set the value of the Grid
Tagged: angular grid, bootstrap grid, javascript grid, jquery grid, jqwidgets grid, jqxgrid id selection
This topic contains 8 replies, has 2 voices, and was last updated by jschultz0614 8 years, 11 months ago.
-
Author
-
Is it possible to dynamically select or set the value of the grid. Not to change the contents, but to automatically select a row with out knowing its index?
Hi jschultz0614,
please provide further information about what exactly do you want to use for the selection(for example, by cell content, by row id, etc.). Also in case you want to select by some data that has duplicates in the grid( for example, a cell value that repeats in many rows), do you want to select just the first occurance or all of them ?
Best Regards,
ChristopherjQWidgets Team
http://www.jqwidgets.comCurrently, all the data in the list is unique by its ID which is a GUID. I need to be able to select the row where the GUID is a certain value.
Hi jschultz0614,
you can achieve that by:
1. Calling the “getrowboundindexbyid” method to get the index of the row by the ID you want.
2. Calling the “selectrow” method by passing the idex to select the row.Here is an example:
https://www.jseditor.io/?key=xb-gridBest Regards,
ChristopherjQWidgets Team
http://www.jqwidgets.comOK,… I think this is a start, however, I do not believe that my grid has a bound index. How do I set this?
This is what I have so far:
var rowIndex = $("#jqxDefaultDiscountAccountDropdownWidget").jqxGrid('getrowboundindexbyid', @Html.Raw(string.Format("\"{0}\"", PayingBills_DefaultDiscountAccount.ToString())));
$(“#jqxDefaultDiscountAccountDropdownWidget”).jqxGrid(‘selectrow’, rowIndex);
which translates to the following at render time:
var rowIndex = $("#jqxDefaultDiscountAccountDropdownWidget").jqxGrid('getrowboundindexbyid', "7c98652e-7941-e611-9c47-c86000a214e4");
$(“#jqxDefaultDiscountAccountDropdownWidget”).jqxGrid(‘selectrow’, rowIndex);
OK,… I just realized that my grid name is not the one supplied in the previous posting. I changed the id to the correct id and now Im getting an error stating: Cannot read property ‘{prop}’ of undefined. I also just realized that I have a set reusable functions for my grids and in one of those functions, I have a bound setting for the selectrow event. Unfortunately, the script is not able to work because the “Object” name is not being passed to the sub function.
One last thing…. These are GUIDs not INT32 so how do I select a row if the rowid is unknown?
I have found a work around until a function is developed:
function GetRowIDOfItemByGUID(GridName, GuidID, DataField)
{
var _Object = $(“#” + GridName);
var dataInformation = $(_Object).jqxGrid(‘getdatainformation’);
for (i = 0; i < dataInformation.rowscount; i++)
{
if($(_Object).jqxGrid(‘getcellvalue’, i, DataField) == GuidID)
{
return i;
}
}
return null;
}and from the main page (this is in razor syntax):
var rowIndex = GetRowIDOfItemByGUID(“jqxDefaultDiscountAccountDropdownGrid”, @Html.Raw(string.Format(“\”{0}\””, PayingBills_DefaultDiscountAccount.ToString())), “AccountIndex”);
$(“#jqxDefaultDiscountAccountDropdownGrid”).jqxGrid(‘selectrow’, rowIndex); -
AuthorPosts
You must be logged in to reply to this topic.