Skip to content

SlickgridReact customDataView is not assigned to this.dataView during initialization #2614

@aasimkhan30

Description

@aasimkhan30

Describe the bug

When SlickgridReact is initialized with a customDataView prop, the component passes that custom DataView to new SlickGrid(...), but it does not assign it to the component's internal this.dataView.

In frameworks/slickgrid-react/src/components/slickgrid-react.tsx, this.dataView is only assigned inside:

if (!this.props.customDataView) {
  this.dataView = new SlickDataView(...)
}

but later in the same initialization() method, the code still uses this.dataView:

if (typeof (this.dataView as SlickDataView).setGrid === 'function') {
  this.dataView.setGrid(this.grid);
}
this.sharedService.dataView = this.dataView;
this.bindDifferentHooks(this.grid, this._options, this.dataView);

This means this.dataView can be undefined when customDataView is supplied, causing initialization to fail or leaving sharedService.dataView / instances.dataView unset.

Reproduction

Use SlickgridReact with a supplied customDataView:

<SlickgridReact
  gridId="grid1"
  columns={columns}
  dataset={[]}
  options={gridOptions}
  customDataView={customDataView}
/>

During initialization(), customDataView is passed to new SlickGrid(...), but this.dataView is never assigned because the assignment only happens in the if (!this.props.customDataView) branch.

Current source reference:

  • frameworks/slickgrid-react/src/components/slickgrid-react.tsx
  • initialization()
  • customDataView branch around lines 484-529 in commit ba7a129f1

Which Framework are you using?

React

Expected behavior

When customDataView is provided, SlickgridReact should use it consistently as the internal DataView reference, e.g. assign:

this.dataView = this.props.customDataView;

before creating the SlickGrid or before any internal this.dataView access.

Actual behavior

customDataView is passed to new SlickGrid(...), but this.dataView remains unset because the internal assignment only happens in the non-custom DataView branch.

Suggested fix

Assign the custom DataView to the internal field when provided:

if (this.props.customDataView) {
  this.dataView = this.props.customDataView;
} else {
  const dataviewInlineFilters = (this._options.dataView && this._options.dataView.inlineFilters) || false;
  let dataViewOptions: Partial<DataViewOption> = { ...this._options.dataView, inlineFilters: dataviewInlineFilters };
  ...
  this.dataView = new SlickDataView<TData>(dataViewOptions as Partial<DataViewOption>, this._eventPubSubService);
  this._eventPubSubService.publish('onDataviewCreated', this.dataView);
}

This keeps later internal references (setGrid, sharedService.dataView, bindDifferentHooks, SlickgridReactInstance.dataView) consistent for both internal and custom DataView cases.

Environment Info

| Executable          | Version |
| ------------------- | ------- |
| Framework used      | React / Slickgrid-React |
| Slickgrid-Universal | master, commit ba7a129f1 |
| TypeScript          | N/A |
| Browser(s)          | N/A |
| System OS           | N/A |

Validations

  • Follow our Code of Conduct
  • Read the Wikis.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion.
  • The provided reproduction is a minimal source-level reproduction of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions