EasyUI Forum
March 29, 2024, 07:30:09 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: adding column and maintaining all properties  (Read 4396 times)
korenanzo
Full Member
***
Posts: 145


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

-- Licensed User --

www.kitelabs.it
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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');
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!