EasyUI Forum
April 19, 2024, 08:13:39 PM *
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 with variable number of columns  (Read 24957 times)
lusabo
Newbie
*
Posts: 8


View Profile
« on: February 29, 2012, 10:50:01 AM »

How to create a datagrid whose number of columns is variable?
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #1 on: March 21, 2012, 01:17:13 AM »

Hi;

Well the columns will be created based on the columns provided to the datagrid:

This will dynamically create 3 columns:

Code:
columns: [[
{field:'xxx',title:'xxx'},
{field:'xxx',title:'xxx'},
{field:'xxx',title:'xxx'},
]]

And this will dynamically create 5 columns:

Code:
columns: [[
{field:'xxx',title:'xxx'},
{field:'xxx',title:'xxx'},
{field:'xxx',title:'xxx'},
{field:'xxx',title:'xxx'},
{field:'xxx',title:'xxx'},
]]

I recall that there's also a demo on how to change the columns under the demo section.

Cheers
Logged

-- Licensed User --
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #2 on: March 23, 2012, 03:03:05 AM »

Hi,

I had no time to study this much but in my project I create complete list of columns but make only part of them visible.
And of course to increase dataload performance I do not load data into hidden columns.

Similar idea could be seen in Demo examples.

//Valery
Logged
Kevin
Jr. Member
**
Posts: 52


View Profile Email
« Reply #3 on: April 04, 2012, 04:40:29 AM »

Hi lusabo

I agree with mzeddd response. Just hide/unhide columns, but it you want to add/remove column, just reinit the datagrid. I'm sure there are better ways to do this, but you should get the idea from the example;
var menuStruct = [];
var menuItems = [];
var menuItem1 = {
   field: 'field1',
   title: 'Title1',
   width: 100
}
var menuItem2 = {
   field: 'field2',
   title: 'Title2',
   width: 105
}

function insertCol() {
   menuStruct.pop();
   menuItems.push(menuItem2);
   menuStruct.push(menuItems);

   $('#myDatagrid').datagrid({
      columns: menuStruct
   });
}

$(function () {
   menuItems.push(menuItem1);
   menuStruct.push(menuItems);

   $('#myDatagrid').datagrid({
      columns: menuStruct,
      fit: false,
      width: 370,
      nowrap: false,
      striped: true,
      collapsible: true,
      url: url
   });
}

To delete a column means you need to remove the menu object from the menuItems array and reinit the datagrid.
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!