Skip to content

Commit

Permalink
Fix #1367/#1862: Column resizeable attribute (#2824)
Browse files Browse the repository at this point in the history
* Fix #1367: Column resizeable attribute

* Update column.js

* Fix #1367: Column resizeable attribute

* Update colresize.js
  • Loading branch information
melloware authored May 12, 2022
1 parent ff3b87a commit 66a2554
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
8 changes: 7 additions & 1 deletion api-generator/components/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,14 @@ const ColumnProps = [
{
name: 'reorderable',
type: 'boolean',
default: 'null',
default: 'true',
description: 'Used to defined reorderableColumns per column when reorderableColumns of table is enabled, defaults to value of reorderableColumns.'
},
{
name: 'resizeable',
type: 'boolean',
default: 'true',
description: 'Used to defined resizeableColumns per column when resizeableColumns of table is enabled, defaults to value of resizeableColumns.'
}
];

Expand Down
18 changes: 18 additions & 0 deletions components/doc/datatable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,12 @@ export const DataTableDemo = () => {
<td>null</td>
<td>Used to defined reorderableColumns per column when reorderableColumns of table is enabled, defaults to value of reorderableColumns.</td>
</tr>
<tr>
<td>resizeable</td>
<td>boolean</td>
<td>null</td>
<td>Used to defined resizeableColumns per column when resizeableColumns of table is enabled, defaults to value of resizeableColumns.</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -2516,6 +2522,18 @@ export const DataTableRowExpansionDemo = () => {
<Column field="quantity" header="Quantity" style={{width:'30%'}}></Column>
</DataTable>
`}
</CodeHighlight>

<p>You can choose which columns are <i>resizeable</i> per column.</p>
<CodeHighlight>
{`
<DataTable value={products} resizableColumns>
<Column field="code" header="Code" style={{width:'20%'}}></Column>
<Column field="name" header="Name" style={{width:'40%'}}></Column>
<Column field="category" header="Category (not resizable)" style={{width:'20%'}} resizeable={false} />
<Column field="quantity" header="Quantity" style={{width:'30%'}}></Column>
</DataTable>
`}
</CodeHighlight>

<h5>Column Reorder</h5>
Expand Down
1 change: 1 addition & 0 deletions components/lib/column/Column.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface ColumnProps {
rowEditor?: boolean;
exportable?: boolean;
reorderable?: boolean;
resizeable?: boolean;
excludeGlobalFilter?: boolean;
onCellEditInit?(e: ColumnEventParams): void;
onCellEditComplete?(e: ColumnEventParams): void;
Expand Down
3 changes: 2 additions & 1 deletion components/lib/column/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ Column.defaultProps = {
rowReorderIcon: 'pi pi-bars',
rowEditor: false,
exportable: true,
reorderable: true
reorderable: true,
resizeable: true
}
2 changes: 1 addition & 1 deletion components/lib/datatable/HeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export const HeaderCell = React.memo((props) => {
const align = getColumnProp('alignHeader') || getColumnProp('align');
const className = classNames(getColumnProp('headerClassName'), getColumnProp('className'), {
'p-sortable-column': getColumnProp('sortable'),
'p-resizable-column': props.resizableColumns,
'p-resizable-column': props.resizableColumns && getColumnProp('resizeable'),
'p-highlight': sortMeta.sorted,
'p-frozen-column': getColumnProp('frozen'),
'p-selection-column': getColumnProp('selectionMode'),
Expand Down
6 changes: 5 additions & 1 deletion components/lib/treetable/TreeTableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export const TreeTableHeader = React.memo((props) => {
}
}

const getColumnProp = (...args) => {
return props.column ? typeof args[0] === 'string' ? props.column.props[args[0]] : (args[0] || props.column).props[args[1]] : null;
}

const createSortIcon = (column, sorted, sortOrder) => {
if (column.props.sortable) {
const sortIcon = sorted ? sortOrder < 0 ? 'pi-sort-amount-down' : 'pi-sort-amount-up-alt' : 'pi-sort-alt';
Expand Down Expand Up @@ -211,7 +215,7 @@ export const TreeTableHeader = React.memo((props) => {
const className = classNames(column.props.headerClassName || column.props.className, {
'p-sortable-column': column.props.sortable,
'p-highlight': sorted,
'p-resizable-column': props.resizableColumns
'p-resizable-column': props.resizableColumns && getColumnProp('resizeable')
});

const resizer = createResizer(column);
Expand Down
12 changes: 11 additions & 1 deletion pages/datatable/colresize.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const DataTableColResizeDemo = () => {
<DataTable value={products} resizableColumns columnResizeMode="fit" showGridlines responsiveLayout="scroll">
<Column field="code" header="Code" style={{width:'20%'}}/>
<Column field="name" header="Name" style={{width:'40%'}}/>
<Column field="category" header="Category" style={{width:'20%'}}/>
<Column field="category" header="Category" style={{width:'20%'}} />
<Column field="quantity" header="Quantity" style={{width:'20%'}}/>
</DataTable>
</div>
Expand All @@ -53,6 +53,16 @@ const DataTableColResizeDemo = () => {
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</div>

<div className="card">
<h5>Choose Resizable Columns</h5>
<DataTable value={products} resizableColumns columnResizeMode="fit" showGridlines responsiveLayout="scroll">
<Column field="code" header="Code" style={{width:'20%'}}/>
<Column field="name" header="Name" style={{width:'40%'}}/>
<Column field="category" header="Category (not resizable)" style={{width:'20%'}} resizeable={false} />
<Column field="quantity" header="Quantity" style={{width:'20%'}}/>
</DataTable>
</div>
</div>

<DataTableColResizeDemoDoc></DataTableColResizeDemoDoc>
Expand Down

0 comments on commit 66a2554

Please sign in to comment.