EasyUI Forum
April 29, 2024, 02:06:02 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: Datagrid options get values from object  (Read 1185 times)
Wojak
Newbie
*
Posts: 48


View Profile Email
« on: February 07, 2023, 01:44:19 PM »

Hi,
How to get all values from options of columns exactly formatter or other that has function inside
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: February 07, 2023, 07:08:08 PM »

Please call this code.
Code:
var dg = $('#dg');
var fields = dg.datagrid('getColumnFields',true).concat(dg.datagrid('getColumnFields',false));
var columns = $.map(fields, function(f){return dg.datagrid('getColumnOption',f)});
console.log(columns);
Logged
Wojak
Newbie
*
Posts: 48


View Profile Email
« Reply #2 on: February 08, 2023, 02:33:08 PM »

Thanks for your answer, but I think I misunderstood the question. I would like to get the code from "formatter" like below because I can't find it in that form.
Code:
formatter: function (value, row, index) {
    if (row.id_tc_bom == null && row.id_tc_object > 0 && row.id_status < 99) {
        return '<a style="color:inherit;" href="javascript:void(0)" onclick="horWinPrzypiszIDBomWin(0,'+row.id+')">'+value+'</a>';
    } else {
        return value;
    }
}
Logged
Wojak
Newbie
*
Posts: 48


View Profile Email
« Reply #3 on: February 08, 2023, 03:13:15 PM »

Ok I found a plugin to JS for JSON https://github.com/vkiryukhin/jsonfn that shows the function inside
Logged
Wojak
Newbie
*
Posts: 48


View Profile Email
« Reply #4 on: February 08, 2023, 04:13:53 PM »

Oh also i found out how to make function from database saved in JSON to run.

Code:
columns.forEach(col=>{if(col.formatter){col.formatter=JSONfn.parse(JSONfn.stringify(col.formatter));}});
If there's a better way to do this, I'd be very happy to help, because at the moment I haven't come up with anything else Cheesy
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!