DataTable - How to select a row and get value of that row

Hi,
is it possible to add a thick box to datatable to select it?
Our goal is to fill data in a datatable to present to the user, then the user should be able to select a row and we need to copy the values of the selected columns's rows in some specific fields.
Is it achievable?
Thanks a lot

Hello @AleStendardo,

Yes, you can add a selection to DataTable and get the selected row data using the code:

const fields = fd.control('DataTable1').widget.columns.map(i => ({
  field: i.field
}));

fields.unshift({
  selectable: true
});

fd.control('DataTable1').widgetOptions = {
  columns: fields,
  //enable single selection
  selectable: 'row'
};
//get the selected row data
//returns an object or an array of objects
fd.control('DataTable1').widget.getSelectedData();

Thanks a lot Margo, it works fine.
Is it also possible to get the numeber of selected row?

@AleStendardo,

You can add a counter so the row data will contain the line number. Find the code example here:

1 Like