Author Topic: Customize Autofit function  (Read 4188 times)

akraines

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 34
    • View Profile
Customize Autofit function
« on: July 25, 2019, 09:02:14 pm »
Is it possible to customise the implementation of the Autofit option?

I'd like to make the autofit function take into account column header and data width to determine an optimal the width of the columns.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6203
    • View Profile
Re: Customize Autofit function
« Reply #1 on: July 26, 2019, 10:17:50 am »
Autofit logic can't be customized and it doesn't need to because it already considers the cell widths in table body and header.

It can be configured with flex option https://paramquery.com/pro/api#option-flex

akraines

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Customize Autofit function
« Reply #2 on: July 29, 2019, 06:24:57 pm »
Perfect!
Thanks

akraines

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Customize Autofit function
« Reply #3 on: July 29, 2019, 07:03:40 pm »
The flex option works very well except that it seems to put all the remaining space in the last column. Am I doing something wrong?
height:"500",
width:"100%",
colModel,
                scrollModel: { autoFit: true },
                groupModel,
                groupOption: function( event, {ui, oldGM, source} ) {
                    const groupModel = this.option("groupModel");                   
                    toggleGroupColumnsVisible( groupModel.dataIndx);                 
                },
flex: { on: true },



        function toggleGroupColumnsVisible(groupColumns) {
            const showGroupColumn = _.isArray(groupColumns) ? groupColumns.length > 0 : groupColumns;
            colModel = showGroupColumn ? [groupColumn, ...colModelFromServer] : colModelFromServer;
            if (_.isArray(groupColumns)){
                const columnsToHide = new Set(groupColumns);
                _.map(colModel, c => c.hidden = columnsToHide.has(c.dataIndx))
            }
            pqGridInstance.option( "colModel", colModel );
            pqGridInstance.refreshView(colModel);   
            pqGridInstance.flex();
        }
« Last Edit: July 29, 2019, 07:13:48 pm by akraines »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6203
    • View Profile
Re: Customize Autofit function
« Reply #4 on: July 29, 2019, 07:41:53 pm »
It's because of scrollModel: { autoFit: true }

you may need to comment/ remove it.

akraines

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Customize Autofit function
« Reply #5 on: July 29, 2019, 08:08:09 pm »
But then it doesn't take 100% width. I'd like it to share the remaining space between all the columns. The truth is that I'd prefer to have autofit false since it makes coulummn resizing work unnaturaly - is there a way to make it use 100% space when flex is true without using autofit.

Thanks.