Title: How to get DataGrid column's value by column number and variable ? Post by: Jonny on May 16, 2015, 08:49:42 AM Dear All,
Currently, If i want to get value from datagrid field, i did like this: row = $("#dg").datagrid("getSelected"); vname=row.productname; Could you please tell me, how to capture value from field using column number & variabel ? Column Number: Imagine the field "productname" located on column number 3 in datagrid Is there any technic to get the value from "productname" by using column number? Imagine --> vname = row.getfromcol(3); Variable: Is there any technic to get the value from "productname" by using string variable? this is my imagination: field="productname"; vname = row.getfromfield(field); Any help would be very appreciated... thank you.. Regards, JONNY Title: Re: How to get DataGrid column's value by column number and variable ? Post by: jarry on May 16, 2015, 04:34:48 PM The following code can achieve this functionality.
Code: function getSelectedValue(dg, field){ Usage example: Code: var v1 = getSelectedValue('#dg', 3); Title: Re: How to get DataGrid column's value by column number and variable ? Post by: Jonny on May 16, 2015, 08:56:46 PM Thank you very much Jarry,
Your solution is very good ( almost perfect ). Both function works and get result succesfull. But, I still unable get data when using variable that is not inside array... For example, I had field name -> "NETPRICE" which is not listed in the datagrid Because this column is not for public / standard user... but it needed when comparing price... Although I can get it using common way: row = $("#dg").datagrid("getSelected"); vname=row.NETPRICE; But I like the way you create that function... So, please help me finalized the function that you gave.. Thanks in advance. Regards, JONNY Title: Re: How to get DataGrid column's value by column number and variable ? Post by: jarry on May 17, 2015, 02:59:50 AM Please try the updated code. If a field does not be defined in the 'columns' or 'frozenColumns' properties, it can not be accessed by field index. But you still can access it by the field name.
Code: var v2 = getSelectedValue('#dg','productname'); Title: Re: How to get DataGrid column's value by column number and variable ? Post by: Jonny on May 17, 2015, 08:20:16 AM Thank you Jarry,
That is the perfect solution for me, no problem with the rule... As always, I get helped successfully in this forum again.. :D Regards, Jonny |