How to pass percentage value to width to React data grid column

Viewed 9465

Below is my Reactdata grid code

    this._columns = [
          {
            key: 'id',
            name: 'ID',
            width: 40
          },
          {
            key: 'task',
            name: 'Title',
            width:100
          },
          {
            key: 'priority',
            name: 'Priority',
            width:100
          },
          {
            key: 'issueType',
            name: 'Issue Type',
            width:100
          },
          {
            key: 'complete',
            name: '% Complete',
            width:100
          },
          {
            key: 'startDate',
            name: 'Start Date',
            width:100
          },
          {
            key: 'completeDate',
            name: 'Expected Complete',
            width:100
          }
        ];

          render() {
        return  (
          <ReactDataGrid
            columns={this._columns}
            rowGetter={this.rowGetter}
            rowsCount={this._rows.length}
            minHeight={500}
            minColumnWidth={120} 
          />);
      }

Using below React data grid: https://github.com/adazzle/react-data-grid

I want to pass width as a percentage, how we can achieve with React data grid. Any help would be appreciated. Thanks

3 Answers

I know maybe it is late but you can achieve this by setting the value as string

const columns = [
  {
    key: 'Month',
    name: 'Mes',
    width: '50%',
  },
  {
    key: 'Tickets',
    name: 'Tickets',
    width: '10%',
  },
 ];

Hope it helps

To make a given column resizable, set column.resizable = true.

If you need to know when a column has been resized, use the onColumnResize prop. This will be triggered when a column is resized and will report the column index and its new width.

These can be saved on the back-end and used to restore column widths when the component is initialized, by setting width key in each column.

pass resizable:true which you want to resize like below.

this._columns = [
  {
    key: 'id',
    name: 'ID',
    resizable: true,
    width: 40
  },
  {
    key: 'task',
    name: 'Title',
    resizable: true
  }]

refer here for more info

To pass with as percentage in a react component you just need to do the following width='100%'.

Related