How can i hide a subgrid if it empty? I tried this solution and this but no luck.
Asked
Active
Viewed 5,835 times
2 Answers
0
Look at the old answer. It seems be exactly what you need.
-
There was nice solution, but isn't exactly what I need. In my case i have rows which should be with subgrid, and should be without subgrid in one table. There are different between them only that in ones presents data in subgrid in other aren't. [Link](http://a-venu.com/?s=&vn_city=&vn_state=&vn_venue_type=&vn_room_setup_type=&vn_guest_rooms_required=&vn_max_mtg_occupanccy=&vn_largest_mtg_rooms=&vn_total_room_sq_ft=&vn_length_minimum_ft=&vn_width_minimum_ft=&vn_height_minimum_ft=) to demo if you scroll down you will see 4 rows which shouldn't be with subgrid – VaL Dec 22 '11 at 15:49
-
BTW, I take your solution for my work. Thanks. But still wait answer ) – VaL Dec 22 '11 at 15:51
0
Based on this and Oleg's answer i resolve my problem. In my table all rows are expanded so code looks like this for main table:
gridComplete: function(){
var table_name = 'table_18';
var myGrid = $('#'+table_name);
var rowIds = myGrid.getDataIDs();
$.each(rowIds, function (index, rowId){
myGrid.expandSubGridRow(rowId);
});
var subGridCells = $("td.sgexpanded",myGrid[0]);
$.each(subGridCells,function(i,value){
$(value).unbind('click').html('');
});
}
In this code i removed click action for expand/collapse subgrids. So they are always open and there is no posibility to collapse them.
Based on this i remove empty subgrids.
loadComplete: function(){//in subgrid
var table_value = $('#'+subgrid_table_id).getGridParam('records');
if(table_value === 0){
$('#'+subgrid_id).parent().parent().remove();
}
}
Maybe exist more simple and elegant solution, but for me it's works as i expected.