Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 889
pareshm Avatar asked Sep 05 '18 09:09

pareshm


People also ask

How do you set the width of a column in Ag grid react?

Enable SizingTurn column resizing on for the grid by setting resizable=true for each column. To set resizing for each column, set resizable=true on the default column definition. The snippet below allows all columns except Address to be resized by explicitly setting each column.

How do you change the width of a column in react?

You need to use a layout hook (useBlockLayout, useAbsoluteLayout or useFlexLayout) so the specified width is applied. Important: all those hooks set a default column width to 150px. You can see an example for react-table v8 in React Example: Column Sizing and for v7 in Full Width Resizable Table. Thank you!

How do you change size of grid in react?

Columns width can be resized by clicking and dragging at the right edge of column header. While dragging, the width of respective column will be resized immediately. Each columns can be auto resized by double clicking at the right edge of column header.

How do you make AG grid responsive in react JS?

The quickest way to achieve a responsive grid is to set the grid's containing div to a percentage. With this simple change the grid will automatically resize based on the div size and columns that can't fit in the viewport will simply be hidden and available to the right via the scrollbar.


Video Answer


2 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

like image 164
Marta Tenés Avatar answered Sep 30 '22 03:09

Marta Tenés


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

like image 43
Amruth Avatar answered Sep 30 '22 03:09

Amruth