EasyUI Forum

General Category => General Discussion => Topic started by: korenanzo on June 20, 2018, 01:00:10 AM



Title: datagrid: adding column and maintaining all properties
Post by: korenanzo on June 20, 2018, 01:00:10 AM
Hi,
I need to add columns in a datagrid;

I know that the only way to do this is recreating the datagrid.

I've also find this

Here is the extended method that can re-create datagrid without sending request.
Code:
$.extend($.fn.datagrid.methods,{
recreate:function(jq){
return jq.each(function(){
var dg = $(this);
var opts = dg.datagrid('options');
var url = opts.url;
var pageNumber = opts.pageNumber;
opts.url = null;
var data = dg.datagrid('getData');
dg.datagrid();
dg.datagrid('loadData',data);
setTimeout(function(){
opts.url = url;
opts.pageNumber = pageNumber;
dg.datagrid('getPager').pagination('refresh',{pageNumber:pageNumber});
},0);
});
}
});
Calling $('#dg').datagrid('recreate') is same as $('#dg').datagrid() but does not re-request data from server.


And it seems to be the solution to my problem, but:

Because of my datagrid has a lot of properties setup (celledit mode, sort, event callbacks,whether striped or not ....), I'd like to know if with that recreate trik all the properties arre maintained, and if not, how to achieve this.

Thanks,

Ric


Title: Re: datagrid: adding column and maintaining all properties
Post by: stworthy on June 20, 2018, 02:35:31 AM
Recreating datagrid will remain all the previous settings. If a feature is applied by calling the 'enable...' method, you should disable it before creating datagrid and enable it again after creating datagrid successfully. The code looks like this:
Code:
var dg = $('#dg');
dg.datagrid('disableCellEditing');
dg.datagrid('recreate');
dg.datagrid('enableCellEditing');