Easyui DataGrid Ajax Real-time refresh dynamically add column names

Source: Internet
Author: User
Tags json


On an implementation of the DataGrid loading column name dynamic Add, due to project requirements, need to set a timer on this page, 3 seconds to refresh, with the DataGrid reload method Refresh will have a splash screen effect, online search on this page to add CSS style method although the Flash screen has a certain improvement, But the effect is still poor, you can see the traces of the refresh. So think of Ajax asynchronous refresh without splash screen effect, first set up a timer
SetInterval ("Freshgrid ()", 3000);
The next implementation of the Refresh Method Greshgrid ();


function freshgrid () {
     //$("#grid").datagrid("reload ");
     var grid = $ ('# grid');
     var options = grid.datagrid ('getPager'). data ("pagination"). options;
     var page = options.pageNumber; // Get the current page number
     var rows = options.pageSize; // Get the set number of rows displayed per page, these two parameters are needed for pagination query
     $ .ajax ({
         type: 'POST',
         url: 'queryResult.action',
         data: {'queryId': $ {param.queryId}, 'rows': rows, 'page': page},
         success: function (data) {
                 $ ('# grid'). datagrid ('loadData', eval ('(' + data + ')'));
             }
     });
} 


The background is returned in the standard JSON format (the last mentioned format).
Write here if the column name is added dynamically at the beginning of loading, there will be no error, but the column name that was added dynamically at the beginning of the project is empty, and then the source of the refreshed Easyui does not refresh the column name, so while the JSON has the corresponding data, it will not be displayed. At this point you need to add a column name to the source of the LoadData. easyUI1.3.2
Find LoadData first, in line 8173.


});
},loaddata:function (jq,data) {
return Jq.each (function () {
_4e5 (this,data);
_562 (this);
});


In _4e5 (this,data), add the resolution of the column name. This method is implemented in 7245 rows


function _4e5 (_4e6,data) {
var _4e7=$.data (_4e6, "DataGrid");
var opts=_4e7.options; 
var dc=_4e7.dc;
Data=opts.loadfilter.call (_4e6,data);
Data.total=parseint (data.total);
_4e7.data=data;
if (data.footer) {
_4e7.footer=data.footer;
}


The code added in it is similar to the one added in the previous section


function _4e5 (_4e6,data) {
var _4e7=$.data (_4e6, "DataGrid");
var opts=_4e7.options;
if (data!=null && data.cols!=null) {  
    var cols = opts.columns[0];        
    var colcount=cols.length;  
    if (colcount==0) {            
       for (var i = 0; i < data.cols.length; i++) {
           var col = {        
               Field:data.cols[i].field,        
               ti Tle:data.cols[i].title,        
               width:data.cols[i].width     
           };        
           Cols.push (col);        
       }        
       UI Add Column        
       if (colcount==0 && opts.columns) {        
           _494 (_4e6);}}      
}  
var dc=_4e7.dc;
Data=opts.loadfilter.call (_4e6,data);
Data.total=parseint (data.total);
_4e7.data=data;
if (data.footer) {
_4e7.footer=data.footer;
}


This enables Ajax to dynamically add a real-time refresh of column names asynchronously.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.