This is a migrated thread and some comments may be shown as answers.

Speed up the autoFitColumn() ?

3 Answers 446 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 08 Feb 2017, 02:13 PM

How can i speed up a autoFitColumn() on multi-headers grid?

In the screenshot you can see that each column fitting make Recalculate Styles. Is it possible to cache width of the fitted column without firing up CSS and then after all columns width are calculated use grid.setOptions() to set columns width with new fitted width?

Also i need to use dirty hack:   hideColumn();showColumn() becouse footer isn't fitted to columns.

Table.prototype.fitColumns = function(){
    var self = this;
    var count = 0;
    var col;
    var selected = this.grid.select().data('uid');
    for (var i = 0; i < this.grid.columns.length; i++) {
        var multi = this.grid.columns[i].columns;
        if (multi){
            _.forEach(multi, function(el, j){
                if (el.columns){
                    _.forEach(el.columns, function(el2, k){
                        col = multi[j].columns[k];
                        if (!col.attributes || (col.attributes && !col.attributes.noFit)) self.grid.autoFitColumn(col);
                    });
                }
                else {
                    col = multi[j];
                    if (!col.attributes || (col.attributes && !col.attributes.noFit)) self.grid.autoFitColumn(col);
                }
            });
        } else {
            col = self.grid.columns[i];
            if (!col.attributes || (col.attributes && !col.attributes.noFit)) self.grid.autoFitColumn(col);
        }
    }
    this.grid.refresh();
    this.fitted = true;
    if (selected) this.grid.select("tr[data-uid='" + selected + "']");
    this.grid.hideColumn(1);
    this.grid.showColumn(1);
};

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 10 Feb 2017, 10:20 AM
Hello Daniel,

Note that if you auto resize all columns this will likely result in having white space on the right of the Grid. Also, resizing the columns one by one is an "expensive" operation from performance perspective. This will become more noticeable with larger number of rows.

Thus, if you you would like to have the columns of the Grid auto resized I would recommend to disable scrolling for the Grid and ensure that it is using automatic table layout.



Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Daniel
Top achievements
Rank 1
answered on 24 Feb 2017, 05:25 PM
Ok, but then when i set overflow to grid container and scrolling it headers are not frozen :/
0
Viktor Tachev
Telerik team
answered on 28 Feb 2017, 12:36 PM
Hello Daniel,

In order for the frozen columns to work as expected you need to ensure that the conditions listed in the following article are met.



Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or