lundi 17 août 2020

how can I write onChange for checkboxes while processing data

I am having array like this

 CONST unit=2;
var data1=[{a:aa, b:bb, c:cc},{a:dd, b:ee, c:ff}, {a:gg, b:hh, c:ii} ];

I'm using material table whose selection value true function to select array values from it

                    <MaterialTable
                            data={data1}
                            onSelectionChange={this.onChange(data)}
                          />

I'm able to write onChange function like this in which selectRow is the row which we select from the material table

 const onChange = (selectRow) =>{
var{ unit } = this.props;
if (selectRow) {
  var values = this.state.newArray.concat(selectRow.map(v => {
    let keys = Object.keys(v);
    return v[keys[unit]];
  }));
  this.setState({
    newArray: values
  }); };

Bsically this function creates the new array which contains the value ["cc", "ff", "ii"] according to unit value.

now how can I write the logic so that new array should be update if I uncheck the value from the table. SelectRow gives the same array when we check and uncheck according to the data.

PS thank you in advance.




Aucun commentaire:

Enregistrer un commentaire