EasyUI Forum
October 17, 2025, 01:14:12 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to get DataGrid column's value by column number and variable ?  (Read 23095 times)
Jonny
Newbie
*
Posts: 38


View Profile Email
« 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



Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 on: May 16, 2015, 04:34:48 PM »

The following code can achieve this functionality.
Code:
function getSelectedValue(dg, field){
    var dg = $(dg);
    var row = dg.datagrid('getSelected');
    if (!row){return undefined;}
    var fields = dg.datagrid('getColumnFields',true).concat(dg.datagrid('getColumnFields',false));
    if (typeof field == 'number'){
        return row[fields[field]];
    } else {
        return row[field];
    }
}

Usage example:
Code:
var v1 = getSelectedValue('#dg', 3);
var v2 = getSelectedValue('#dg','productname');
« Last Edit: May 17, 2015, 02:55:32 AM by jarry » Logged
Jonny
Newbie
*
Posts: 38


View Profile Email
« Reply #2 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
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #3 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');
var v3 = getSelectedValue('#dg','NETPRICE');
Logged
Jonny
Newbie
*
Posts: 38


View Profile Email
« Reply #4 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..
 Cheesy


Regards,
Jonny
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!