Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generics to type data and newData in DataTableRowEditSaveEvent, DataTableRowEditCancelEvent and DataTableRowEditInitEvent interfaces. DataTable component #7194

Closed
lucasdavidferrero opened this issue Feb 5, 2025 · 1 comment
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@lucasdavidferrero
Copy link

lucasdavidferrero commented Feb 5, 2025

The current definition is:

export interface DataTableRowEditSaveEvent {
  originalEvent: Event  
  data: any
  newData: any
  field: string
  index: number
}

An example handling @row-edit-save in DataTable component with current typescript definitions:

async function onRowEditSave (event: DataTableRowEditSaveEvent) {
  let { newData, data, index } = event;
  const newName = newData.fullname // We don't get autocomplete here. It's also unsafe if doing comparations
  const oldName = data.fullname
  if (newName !== oldName) {
    rowData.value[index] = newData  // assigning is unsafe here. rowData entry's type should match newData's type.
  }
}

I think adding a generic for typing data and newData properties will improve DX:

export interface DataTableRowEditSaveEvent<TData> {
  originalEvent: Event  
  data: TData
  newData: TData
  field: string
  index: number
}

This situation of having data and newData happens in other data structures related with the DataTable component such as: DataTableCellEditCompleteEvent, DataTableCellEditCancelEvent, DataTableCellEditInitEvent, DataTableRowCollapseEvent, DataTableRowExpandEvent among others.

Finally but not least, we don't get code suggestion or liting in template when accesing information from a slot prop. Like so:

<Column header="Price" style="min-width: 150px">
  <template #body="{ data }">
      {{ formatPrice(data.price_with_taxes) }}
  </template>
</Column>

We're not getting suggestions when accessing data in template, that increases the change of introduce bugs. It'll really nice that we can also bring a solution to this.

It was discussed here some time ago: Discussion

@tugcekucukoglu tugcekucukoglu added the Resolution: Help Wanted Issue or pull request requires extra help and feedback label Feb 6, 2025
Copy link

github-actions bot commented Feb 6, 2025

Due to PrimeTek's demanding roadmap for PrimeVue and the limited bandwidth of the core team, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. ✨ Thank you for your contribution! ✨

SamVanini added a commit to SamVanini/primevue that referenced this issue Feb 6, 2025
@tugcekucukoglu tugcekucukoglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Resolution: Help Wanted Issue or pull request requires extra help and feedback labels Feb 7, 2025
@tugcekucukoglu tugcekucukoglu added this to the 4.3.0 milestone Feb 7, 2025
@tugcekucukoglu tugcekucukoglu self-assigned this Feb 7, 2025
@github-project-automation github-project-automation bot moved this to Review in PrimeVue Feb 7, 2025
tugcekucukoglu added a commit that referenced this issue Feb 7, 2025
feat(datatable): Added generics to type data and newData #7194
@github-project-automation github-project-automation bot moved this from Review to Done in PrimeVue Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
Status: Done
Development

No branches or pull requests

2 participants