easyui create columns dynamically

easyui can dynamically change the columns, but what if there’s a lot of columns need to create? or create columns based dynamic data or server side data? here’s a very simple example:

here we generate 30 or 31 columns from days of current month:

$(function(){
$(‘#wxddg’).datagrid({

onClickRow:function(index,data){
var row=$(‘#wxddg’).datagrid(‘getSelected’);
}
});
gencol();
})

function gencol(){
var strdate = new Date();
var stryear = strdate.getFullYear();
var strmonth = strdate.getMonth() + 1;
var daynum = (new Date(stryear,strmonth,0)).getDate();
var colitems = [];
var colstruct = [];
var dycols1 = {field:’id’,hidden:true};
var dycols2 = {field:’prop’,width:’60’};
colitems.push(dycols1);
colitems.push(dycols2);
for(var i=1;i<=daynum;i++){
colitems.push({field:” + i + ”,title:”+i+”,width:’50’});
}
colstruct.push(colitems);
$(‘#wxddg’).datagrid({
columns:colstruct
});
}

Snap1

 

//reference:

http://www.jeasyui.com/forum/index.php?topic=2197.0

http://www.jeasyui.com/forum/index.php?topic=286.0

This entry was posted in Computer, javascript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s