EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Wojak on February 07, 2023, 01:44:19 PM



Title: Datagrid options get values from object
Post by: Wojak 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


Title: Re: Datagrid options get values from object
Post by: jarry 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);


Title: Re: Datagrid options get values from object
Post by: Wojak 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;
    }
}


Title: Re: Datagrid options get values from object
Post by: Wojak on February 08, 2023, 03:13:15 PM
Ok I found a plugin to JS for JSON https://github.com/vkiryukhin/jsonfn (https://github.com/vkiryukhin/jsonfn) that shows the function inside


Title: Re: Datagrid options get values from object
Post by: Wojak 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 :D