EasyUI Forum
April 24, 2024, 11:11:20 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: create dynamically datagrig  (Read 16317 times)
haltman
Newbie
*
Posts: 5


View Profile
« on: April 25, 2012, 01:55:26 AM »

Does exist a way to create dynamically a datagrid? I mean to post columns and rows with jquery ajax functions like $.post or $.getJSON

thanks in advance
ciao
h.
Logged
Ellipsis
Full Member
***
Posts: 113


View Profile WWW
« Reply #1 on: December 04, 2012, 12:18:39 PM »

I would like the Same feature, it would be enough to be able to create the column of a datagrid with a Json file.

Seems to be pretty straightforward, coverting json to a multidimension array, but an easyui method would be the best way i suppose.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 on: December 05, 2012, 12:40:50 AM »

The 'loadFilter' function will be called before data loaded into datagrid. Here is the simple load filter functionality to dynamic create columns.

Code:
<table class="easyui-datagrid" data-options="loadFilter: loadFilter">
</table>

function loadFilter(data){
if (!this.columns && data.columns){
this.columns = data.columns;
var opts = $(this).datagrid('options');
var url = opts.url;
$(this).datagrid({columns:data.columns,url:null});
setTimeout(function(){
opts.url = url;
},0);
}
return data;
}

The json data to be loaded must contains 'columns' definition, such as:

Code:
{"total":1,"rows":[{...}],"columns":[[...]]}
Logged
Ellipsis
Full Member
***
Posts: 113


View Profile WWW
« Reply #3 on: December 05, 2012, 09:09:19 AM »

Ok, got it working.

I have chosen to build a separate method for retrieving columndata and use underscore.js to translate the json to an array [[]] that holds the objects. (many possible columns needed, so I retrieve them all and cache them)

The loadfilter is usable in a whole lot of other scenario's, so I'll try that soon. 
Thank you.

ps. I posted a question about a loadMsg hanging when data retrieve fails, if you have some tips....
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!