react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

Select Filter template given in the website not working. TypeError: Cannot read property 'value' of undefined

Open cssher opened this issue 6 years ago • 3 comments

//Here is my array on objects which denotes my column titles.

const selectOptionsArr = [
  {
    value: 0,
    label: "Best Seller"
  },
  {
    value: 1,
    label: "Evergreen"
  },
  {
    value: 2,
    label: "Old Category-No recent demand"
  },
  {
    value: 3,
    label: "New Category"
  }
];




//Here I am tryin to put the filter function according to the given template.

[...,    dataField: "seg",
    text: "Segment",
    sort: true,
    formatter: cell =>
      selectOptionsArr.filter(opt => opt.value === cell)[0].label|| "",
    filter: selectFilter({
      options: selectOptionsArr
    })
  }
];




//Here I am applying the filter:

 <BootstrapTable
      keyField="id"
      data={rowData}
      columns={columns}
      defaultSorted={defaultSorted}
      pagination={paginationFactory()}
      filter={filterFactory()}
      striped
      hover
      condensed
    />


//Throws this error:

TypeError: Cannot read property 'label' of undefined
formatter
C:/Users/Desktop/data-extraction/e-commerce-data/src/table/BootTable.js:79
  76 | dataField: "seg",
  77 | text: "Segment",
  78 | sort: true,
> 79 | formatter: cell =>
     | ^  80 |   selectOptionsArr.filter(opt => opt.value === cell)[0].label|| "",
  81 | filter: selectFilter({
  82 |   options: selectOptionsArr

Please look into the matter.

cssher avatar Dec 16 '19 16:12 cssher

@cssher, did you find out the solutions for this?

sudheer0725 avatar Feb 25 '20 17:02 sudheer0725

Same issue, been searching for hours. As soon as I put any filter on a column, I get the error (where 'value' = name of column)

DylanBowden avatar Aug 07 '20 13:08 DylanBowden

Figured it out with the help of the examples https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples/column-filter and another issue https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/1345

I was also using ToolkitProvider with the same columns property which was the one actually getting confused by the filtering. Hope this helps someone

DylanBowden avatar Aug 07 '20 14:08 DylanBowden