How can I set minimum width for Data Grid columns?

I have a data grid with dynamic numbers of columns and below are my requirements.

  1. The first column is header column and the width is fixed to 100px.
  2. The rest columns are body columns and their number can be increased and decreased on user interaction. They have equally distributed width, which is calc((100% - 100px(header column width)) / (number of columns - 1)).
  3. The body columns must be at least 128px wide and should stretch when extra space is given.
  4. The table's width is 100%.
  5. If the sum of column widths overflows table width, table gets horizontal scroll bar.

I've checked the document but haven't found a solution yet.
I'm looking forward to hearing from you soon.

Thanks in advance.

Regard,
Hyewon

1 Reply

SI Santhosh Iruthayaraj Syncfusion Team December 14, 2023 02:49 PM UTC

Hi Hyewon,


Greetings from Syncfusion support.


From your query, we understand that you want to define a fixed width of 100px for the first column and a minimum width of 128px for all other columns. This can be accomplished by defining the width and min-width CSS properties for the Grid column from the column groups. Below, you'll find a code snippet and sample for your reference:


[index.css]

 

/* to set min-width for all columns */

.e-grid .e-content col,

.e-grid .e-headercontent col {

  min-width128px;

}

 

/* to set width for first column */

.e-grid .e-content col:first-child,

.e-grid .e-headercontent col:first-child {

  width100px;

  min-width100px;

}

 


Sample: https://stackblitz.com/edit/react-grid-with-columns-width-and-minwidth


In the provided sample, we've specified a minimum width of 128px for all columns and set the 100px width for the first column while also overriding its minimum width. Background colors have been included for the columns to visually demonstrate the width distinction between the first column and the others. Additionally, the sample illustrates the variation in width when resizing columns, and a horizontal scrollbar will appear as needed if the columns cannot fit.


Please feel free to reach out if you have any further questions.


Regards,
Santhosh I


Loader.
Up arrow icon