We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Column width

I would like to set the width of the column with javascript according to window size. I've tried the following javascript code but it does not work:
    var treegridObj = $("#treeGrid").data("ejTreeGrid");
    var numColumns = treegridObj.model.columns.length - 2;
    var swidth1 = $(window).width() - lOffset - rOffset;
    var colWidth = (swidth1 - 445) / numColumns;
    for (var i = 2; i < treegridObj.model.columns.length; i++) {
        treegridObj.model.columns[i].width = 10;
        treegridObj._columnsWidthCollection[i] = 10;
    }
    treegridObj.refreshContent();
    treegridObj.renderRecords();

Can you help me? Thanks.
Best regards.

1 Reply

JD Jayakumar Duraisamy Syncfusion Team September 16, 2015 01:32 PM UTC

Hi Cosimo,
Currently there is no built-in support in TreeGrid to change the width of the columns on resizing browser window, without re-rendering the TreeGrid widget . But we can provide a workaround for your requirement at present , please find the below code example to achieve your requirement,

var treegridObj = $("#Treegrid").data("ejTreeGrid");

              

                for (var i = 2; i < treegridObj.model.columns.length; i++) {

                    treegridObj.model.columns[i].width = 10;

                    treegridObj._columnsWidthCollection[i] = 10;    

                }


                treegridObj.setWidthToColumns();

In addition to that set EnableResize="true" for dynamic window resize.



We have prepared a sample regarding this , please find the sample in the below location,

Sample link: http://www.syncfusion.com/downloads/support/forum/120263/ze/TreeGridSample-1817366911
We have considered your requirement to change the column width dynamically on window resize as feature request and have logged a feature request regarding this.

A support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents

Please let us know if you require further assistance on this.
 Regards,
Jayakumar Duraisamy


Loader.
Up arrow icon