EasyUI Forum
May 17, 2024, 10:20:25 AM *
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 Footer Rows not updating on last item delete from Datagrid [SOLVED]  (Read 15714 times)
mcenal
Newbie
*
Posts: 10


View Profile
« on: May 13, 2014, 11:10:37 AM »

I've got a complicated datagrid based upon the edit grid.  The data loads from json via a database and shows up on the page.  When the json returns an empty value on page load '[]' it shows up correctly as the datagrid with no footer rows.  However if I add a record and then delete one, not only does the footer rows remain visible but also does not update its value.

I'm trying to get the datagrid to do one of the following:
reload the datagrid correctly and show properly
give me a count of the rows in the datagrid so I can find out if it is zero and kick the user over to a different page.

Code:
function destroyItem(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to remove this row?',function(r){
if (r){
var index = $('#dg').datagrid('getRowIndex',row);
jqab = $.post('destroy_row.php',{idhz_timesheets:row.idhz_timesheets},function(){
$('#dg').datagrid('deleteRow',index);
});
jqab.always(function(){
getHours($('#userid').val());
});
}
                           //This is the line that is misbehaving.
$('#dg').datagrid('reload');
});

}

}

Here's the json that is returned from the datagrid load with 1 record.  It will load [] if it is empty.
Code:
{"total":1,"rows":[{"idhz_timesheets":"211","user":"Test User","joblevel":"Foreman","isForeman":"1","isJourneyman":"0","isApprentice":"0","taskcode":"0100-Site","hours":"7.00","date":"2014-05-01","comments":"7"}],"footer":[ {},{"taskcode":"Foreman Hours :","hours":"7.00"},{"taskcode":"Journeyman Hours:","hours":"0.00"},{"taskcode":"Apprentice Hours :","hours":"0.00"},{"taskcode":"Total Hours :","hours":"7.00"}]}

« Last Edit: May 22, 2014, 10:54:34 AM by mcenal » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 13, 2014, 07:46:44 PM »

Notice that you are calling 'reload' method to load the datagrid. The json data returned from your server contains 'footer', this will cause the appearance of footer rows. To display only body rows, you need to remove the 'footer' from your json data.
Logged
mcenal
Newbie
*
Posts: 10


View Profile
« Reply #2 on: May 13, 2014, 08:19:36 PM »

Ahh, but as I said in my post, the json returns [] which is an empty json if that last line has been deleted.  Still it doesn't delete correctly. 

Could it be my reload is called too early?  Or is the return value of [] invalid?

Or is it something deeper?



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


View Profile Email
« Reply #3 on: May 13, 2014, 08:29:29 PM »

When calling 'reload' method, all the data will be reloaded using the new json data returned from your server. You must make sure that the server can return correct data, including body rows and footer rows.
« Last Edit: May 13, 2014, 08:31:13 PM by stworthy » Logged
mcenal
Newbie
*
Posts: 10


View Profile
« Reply #4 on: May 14, 2014, 08:10:33 AM »

I've tested it and from every angle it looks like the json returned is in fact [] which should empty out the datagrid but the footer rows are not updating correctly when an empty dataset is returned.  Yet, when there is no footer (on page load with empty dataset) it hides the footer rows correctly.

I basically used the code directly from the CRUD datagrid with row editing capabilities and footer rows turned on. 

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


View Profile Email
« Reply #5 on: May 14, 2014, 08:37:34 AM »

Please refer to this example http://jsfiddle.net/DA3kU/
Logged
mcenal
Newbie
*
Posts: 10


View Profile
« Reply #6 on: May 14, 2014, 09:05:49 AM »

Okay, so the empty JSON return has to be more than just [].

See example for what I was doing.

The third case was the one that I am currently doing.  I'll switch it over to the 4th case as that seems to work correctly.

http://jsfiddle.net/DA3kU/8/

Code:
//case 3
var data3 = [];
//case 4
var data4 = {total:0,rows:[],footer:[]};

update:  Nope.  Not working right.  Darn it.

I'm trying to add the code to another case but the deletion function isn't working right.
Code:
$('btn5').click(function(){
var row = $('#dg').datagrid('getSelected');
var index = $('#dg').datagrid('getRowIndex',row);
$('#dg').datagrid('deleteRow',index)
});

See example http://jsfiddle.net/DA3kU/11/
« Last Edit: May 14, 2014, 09:24:29 AM by mcenal » Logged
mcenal
Newbie
*
Posts: 10


View Profile
« Reply #7 on: May 22, 2014, 10:53:59 AM »

Finally found a solution that actually works.

This line deletes the entire datagrid so if it is supposed to be empty it will actually empty out.  A bit overkill but it does actually work.
Code:
$('#dg').datagrid('loadData',[]);

This line is the one I've been looking for.  It will also do the same to empty out the footer.  Also a bit overkill but again it does actually work.
Code:
$('#dg').datagrid('reloadFooter',[]);
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!