EasyUI Forum
May 16, 2024, 05:28:23 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:onLoadSuccess() question  (Read 13667 times)
mzeddd
Full Member
***
Posts: 223



View Profile
« on: April 10, 2014, 07:50:31 AM »

Hi,

I have small problem.

I use onLoadSuccess() in order to understand when Data is loaded so I could update menus to fit current data.
Everything is fine, but I get problem in case of this:

1) I load data into DataGrid (using URL)
2) select any record
3) call any action to update data on DB side
4) reload DataGrid content using "reload" method
5) selected record stays selected (what is really-very good)
6) call "menuUpdater" function using onLoadSuccess() event.

But as soon as I need to update my menus in accordance with what is selected now I check what is selected now via "getSelections"
I check parameters of my selected record but the value I'm interesting in is old. (the same as I had in step #2)

How can I understand when DataGrid is completely loaded and ready?

Any event like "onAfterLoad"?

Currently I see only one way - use setTimeout() function, but I don't like this solutions so much.

Thanks

//Valery






Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: April 10, 2014, 07:19:18 PM »

Please try to override the $.fn.datagrid.defaults.loader to use the 'onLoadSuccess' event.
Code:
<script>
$.fn.datagrid.defaults.loader = function(param, success, error){
var target = this;
var opts = $(target).datagrid('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
var onLoadSuccess = opts.onLoadSuccess;
opts.onLoadSuccess = function(){};
success(data);
opts.onLoadSuccess = onLoadSuccess;
opts.onLoadSuccess.call(target, data);
},
error: function(){
error.apply(this, arguments);
}
});
};
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #2 on: April 11, 2014, 01:17:12 AM »

Hi,

Thanks stworthy.

This is what I've been looking for.

//Valery
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #3 on: April 14, 2014, 02:24:46 AM »

Hi stworthy,

Can this code be turned into new event?
Overriding of existing functions can work without any problems only some not very long time.
It is not safe in long term perspective because we could not predict how our code will work with new EasyUI version(s)

//V
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: April 14, 2014, 07:30:04 AM »

The 'onLoadSuccess' event will be improved in next version to support this feature. You can download the patch file from http://www.jeasyui.com/download/downloads/jquery-easyui-1.3.6-patch.zip. The features in this patch will be integrated into next version.
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #5 on: April 14, 2014, 08:25:26 AM »

Thank you stworthy.

BTW, I like your new way of making incremental patches instead of updating separate plugins.

//V
Logged
zh_CN
Newbie
*
Posts: 32



View Profile Email
« Reply #6 on: April 14, 2014, 06:42:03 PM »

great!
Logged

From the great China
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!