EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Bin on November 05, 2015, 05:03:29 AM



Title: create columns in SubGrid from a JSONObject.
Post by: Bin on November 05, 2015, 05:03:29 AM
hello all,

I am new to easyui and encounter  a problem with DataGrid when trying to create columns from a JSONObject in SubGrid.

Here's my Java script:

onExpandRow: function(index,row){
                var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
                ddv.datagrid({
                    url:'FFDDR!rowExpend?s_PID='+row.ProtocolId,
                    loadMsg:'Loading ...',
                    fitColumns:true,
                    singleSelect:true,
                    rownumbers:true,
                    onResize:function(){
                        $('#dg').datagrid('fixDetailRowHeight',index);
                        $('#dg').datagrid('fixRowHeight',index);
                    },
                    onLoadSuccess:function(data, param){
                        ddv.datagrid({
                            columns:[data.columns]                       //Columns are created, but NOT shown in SubGrid
                        });
                        ddv.datagrid("loadData", data.rows);        //Data can be loaded to table and will show in SubGrid
                        setTimeout(function(){                                  
                            $('#dg').datagrid('fixDetailRowHeight',index);
                            $('#dg').datagrid('fixRowHeight',index);
                        },0);
                    }
                });

[data.columns] looks like this:
"columns":[{"field":"sequence_nr","title":"sequence_nr","width":100},{"field":"kind_of_test","title":"kind_of_test","width":100}]


Title: Re: create columns in SubGrid from a JSONObject.
Post by: stworthy on November 05, 2015, 07:25:17 AM
Please try this:
Code:
onExpandRow: function(index,row){
var ddv = $(this).datagrid('getRowDetail',index).find('.ddv');
$.ajax({
url: 'FFDDR!rowExpend?s_PID='+row.ProtocolId,
dataType: 'json',
// ...
success: function(data){
ddv.datagrid({
columns: [data.columns],
data: data.rows,
// ...
});
$('#dg').datagrid('fixDetailRowHeight',index);
}
})
}


Title: Re: create columns in SubGrid from a JSONObject.
Post by: Bin on November 05, 2015, 06:25:39 PM
Hello administrator,

Many thanks for your kind help.
It works perfectly.   :) :) :)


Thanks & Regards,
Bin