How to enable resize in oj-data-grid

We can enable resize in oj-data-grid by adding the following html code to <oj-data-grid>:

<oj-data-grid
  id="datagrid"
  style="width:100%;height:400px"
  aria-label="My Data Grid"
  data='{{ salaryDataADP }}'
  header.column.style="[[ headerColStyle ]]"
  header.column.resizable.width="enable"
  header.column.resizable.height="enable"
  header.row.resizable.width="enable"
  header.row.resizable.height="enable"
  header.column.class-name="oj-helper-justify-content-flex-start"
  cell.class-name="oj-helper-justify-content-flex-start"
>
  <oj-menu slot="contextMenu" aria-label="Employee Edit">
    <oj-option id="resizeWidth" value="Resize Width"
      data-oj-command="oj-datagrid-resizeWidth"></oj-option>
    <oj-option id="resizeHeight" value="Resize Height"
      data-oj-command="oj-datagrid-resizeHeight"></oj-option>
    <oj-option id="resizeFitToContent" value="Resize Fit To Content"
      data-oj-command="oj-datagrid-resizeFitToContent"></oj-option>
  </oj-menu>
</oj-data-grid>

The following attributes on the header will allow resizing. When hovering on a border, the user can resize the row or column height or width.

<oj-data-grid
  header.column.resizable.width="enable"
  header.column.resizable.height="enable"
  header.row.resizable.width="enable"
  header.row.resizable.height="enable"
>
</oj-data-grid>

To add an additional right-click menu, we can add the below code. The user can right-click and click on Resize width, and enter a desired width, like 100 or 200.

<oj-menu slot="contextMenu" aria-label="Employee Edit">
    <oj-option id="resizeWidth" value="Resize Width"
      data-oj-command="oj-datagrid-resizeWidth"></oj-option>
    <oj-option id="resizeHeight" value="Resize Height"
      data-oj-command="oj-datagrid-resizeHeight"></oj-option>
    <oj-option id="resizeFitToContent" value="Resize Fit To Content"
      data-oj-command="oj-datagrid-resizeFitToContent"></oj-option>
  </oj-menu>

There are other commands available, like below ( see the jsdoc link for more information ). Few features are supported only in latest version of JET

Default Functiondata-oj-command value
Resize menu (contains width and height resize)oj-datagrid-resize
Sort Row menu (contains ascending and descending sort)oj-datagrid-sortRow
Sort Column menu (contains ascending and descending sort)oj-datagrid-sortCol
Resize Widthoj-datagrid-resizeWidth
Resize Heightoj-datagrid-resizeHeight
Resize Fit To Contentoj-datagrid-resizeFitToContent
Sort Row Ascendingoj-datagrid-sortRowAsc
Sort Row Descendingoj-datagrid-sortRowDsc
Sort Column Ascendingoj-datagrid-sortColAsc
Sort Column Descendingoj-datagrid-sortColDsc
Cut (for reordering)oj-datagrid-cut
Paste (for reordering)oj-datagrid-paste
CutCells (for data transferring)oj-datagrid-cutCells
CopyCells (for data transferring)oj-datagrid-copyCells
PasteCells (for data transferring)oj-datagrid-pasteCells
Filloj-datagrid-fillCells
Select Multiple Cells on Touch Deviceoj-datagrid-discontiguousSelection
Freeze Columnsoj-datagrid-freezeCol
Freeze Rowsoj-datagrid-freezeRow
Unfreeze Columnsoj-datagrid-unfreezeColumn
Unfreeze Rowsoj-datagrid-unfreezeRow
Hide Columnsoj-datagrid-hideCol
Unhide Columnsoj-datagrid-unhideCol

Screenshots

Live application URL: https://khalil232.com/apps/ojet-apps/?ojr=data-grid-example

References:

helper classes: https://www.oracle.com/webfolder/technetwork/jet/jsdocs/Helpers.html

jet cookbook: https://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=dataGrid&demo=resizing

link for oj-data-commands: https://www.oracle.com/webfolder/technetwork/jet/jsdocs/oj.ojDataGrid.html#contextmenu-section

About the Author

khalil

Hi, I'm Khalil, a passionate front-end developer with over 8 years of experience in web development. I specialize in building interactive, user-friendly websites using technologies like JavaScript, HTML, CSS, and Java.

I've had the opportunity to work on a variety of projects across different industries, helping businesses create modern and responsive web applications.

Outside of coding, I enjoy exploring the latest trends in design and tech, as well as sharing knowledge with others. I'm always looking for new challenges to grow my skills and make a positive impact in the tech community

You may also like these