Angular ng-grid row height

前端 未结 6 2118
梦谈多话
梦谈多话 2020-12-09 09:29

is there any way to apply the height of the row in ng-grid according to its content. there is one option rowHeight which is changed the height of all row. But I want dynamic

6条回答
  •  执笔经年
    2020-12-09 10:04

    it's not the sexiest thing in the world and I doubt it's that performant but this does the trick:

    function flexRowHeight() {
        var self = this;
        self.grid = null;
        self.scope = null;
        self.init = function (scope, grid, services) {
            self.domUtilityService = services.DomUtilityService;
            self.grid = grid;
            self.scope = scope;
    
            var adjust = function() {
                setTimeout(function(){
                    var row = $(self.grid.$canvas).find('.ngRow'),
                        offs;
                    row.each(function(){
                        var mh = 0,
                            s = angular.element(this).scope();
    
                        $(this).find('> div').each(function(){
                            var h = $(this)[0].scrollHeight;
                            if(h > mh)
                                mh = h
    
                            $(this).css('height','100%');
                        });
    
                        $(this).height(mh)
    
                        if(offs)
                            $(this).css('top',offs + 'px');
    
                        offs = $(this).position().top + mh;
                        self.scope.$apply(function(){
                            s.rowHeight = mh;
                        });
                    });
                },1);
            }
    
            self.scope.$watch(self.grid.config.data, adjust, true);
        }
    }
    

    execute using plugins in options:

    plugins: [new flexRowHeight()]
    

提交回复
热议问题