EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Max Lamda on November 04, 2015, 09:35:15 AM



Title: Change behavior of propertygrid groups to be like an accordion
Post by: Max Lamda on November 04, 2015, 09:35:15 AM
I just did a little change, that the datagrid-groups can only be opened exclusively:

onLoadSuccess: function() {

   var groupcount = 5;
   // Just use the correct number here ...
   // in Version 1.4.4 you can get the count via 'groups' method

   $(this).propertygrid('collapseGroup');
   $(this).propertygrid('expandGroup',0);

   var dg=this;
   $(this).parent().find('.datagrid-row-expander').on('click', function() {
      group=$(this).parents('.datagrid-group').attr('group-index');
      for(var i=0;i<groupcount;i++) {
         if(i!=group) {
            $(dg).propertygrid('collapseGroup', i);
         }
      }
   });
}


Title: Re: Change behavior of propertygrid groups to be like an accordion
Post by: stworthy on November 04, 2015, 05:08:20 PM
Another better way to achieve this functionality is to override the 'expandGroup' method. Please try this:
Code:
(function($){
var expandGroup = $.fn.datagrid.methods.expandGroup;
$.fn.datagrid.methods.expandGroup = function(jq, groupIndex){
return jq.each(function(){
var pg = $(this);
var groups  = pg.datagrid('groups');
for(var i=0; i<groups.length; i++){
if (i != groupIndex){
pg.datagrid('collapseGroup', i);
} else {
expandGroup($(this), i);
}
}
})
}
})(jQuery);


Title: Re: Change behavior of propertygrid groups to be like an accordion
Post by: Max Lamda on November 05, 2015, 04:34:30 AM
Yes, thanks, but this would change the behavior for all propertygrids in my application.