Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by ymikhel on Jun 10, 2008 04:13
open dhtmlx forum
Question: Resizing dynamic columns to fix content width - Part II

Hello,

According to your reply (http://dhtmlx.com/docs/products/kb/index.php?s=normal&q=3566&a=4958)
it is only possible to define fixed width for all the columns except one in case I'd like to be able to resize
these columns later. This is not an option in my case, so I ready to omit the resizing feature. But it is a
must to have columns that adjust their width according to the content (both ways - shrink and grow),
and fill all the available table width. It would be desirable to respond to the change of the table
container div width (as a result of window resize, for example) and fill again the new table width.
Is this possible? Right now I am running the following configuration XML, but the columns
not adjusted to fit content width, and after table container div resize I have to resize any column to make
the last one fill the available space.

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <head>
        <column align="center" id="E_DATE" sort="date" type="ro" width="150"><![CDATA[Date]]></column>
        <column align="center" id="E_CODE" sort="str" type="ro" width="150"><![CDATA[Error Code]]></column>
        <column align="center" id="E_DESC" sort="str" type="ro" width="150"><![CDATA[Description]]></column>
        <column align="center" id="E_REPORTER" sort="str" type="ro" width="150"><![CDATA[Reporter]]></column>
        <column align="center" id="E_SERVER" sort="str" type="ro" width="*"><![CDATA[Server]]></column>
    </head>
    <settings>
        <colwidth>px</colwidth>
    </settings>
    <beforeInit>
        <call command="enableResizing">
            <param>true</param>
            <param>true</param>
            <param>true</param>
            <param>true</param>
            <param>true</param>
        </call>
    </beforeInit>
    <afterInit>
        <call command="adjustColumnSize">
            <param>0</param>
        </call>
        <call command="adjustColumnSize">
            <param>1</param>
        </call>
        <call command="adjustColumnSize">
            <param>2</param>
        </call>
        <call command="adjustColumnSize">
            <param>3</param>
        </call>
        <call command="adjustColumnSize">
            <param>4</param>
        </call>
    </afterInit>
    <row id="573">
        <cell id="E_CODE"><![CDATA[INFO]]></cell>
        <cell id="E_DATE"><![CDATA[06/05/2008 10:50]]></cell>
        <cell id="E_DESC"><![CDATA[Some long cell data Some long cell data Some long cell data Some long cell data Some long cell data Some long cell data ]]></cell>
        <cell id="E_REPORTER"><![CDATA[Some data]]></cell>
        <cell id="E_SERVER"><![CDATA[More data]]></cell>
    </row>
</rows>

Regards,
Yuri
Answer posted by Support on Jun 10, 2008 08:22
>> it is only possible to define fixed width for all the columns except one in case I'd like to be able to resize these columns later.
This is correct, the column must have fixed width if you plan to resize it.

>>But it is a must to have columns that adjust their width according to the content (both ways - shrink and grow), and fill all the available table width
The provided  requirements are mutual exclusive - the column can't adjust its size to the inner content , and adjust its size to fill all available space in grid.
The existing design allows two solution
    a) define single flexible column ( width="*" ) and use adjustColumnSize against other columns - in such case all columns will be autosized to data, and column marked as flexible - take all available space
    b) use enableAutoWidth and adjustColumnSize  against all columns - in such case all columns will be adjusted by data size, and grid itself will change size to prevent empty space or scroll.
    c) you can define initial width in percents -  in such case columns will correctly increase width on window resizing, but they will ignore size of data in them.
   
>>and after table container div resize I have to resize any column to make the last one fill the available space.
The grid is not able to detect the resize of parent container, if you resizing parent container by some custom code just add
    grid.setSizes()
after it, this command will force grid sizes update.

>> I am running the following configuration XML, but the columns not adjusted to fit content width
The situation is next - the command from afterInit section called when configuration already loaded, but data part of grid not filled yet, so on moment of call - there is no data, which can be used for column adjusting. Basically the command need to be called from after-loading handler in js code, while call from XML can be done technically - it can't be done with correct timing.