1

I am using Material-table (https://material-table.com/#/) for my project. I have implemented the "detail panel" feature (https://material-table.com/#/docs/features/detail-panel) and have enabled search feature as well.

To my knowledge, the "search" function will only search against "string" values in any column in the table.

My detail panel contains text inside of an html pre tag.

detailPanel={rowData => {
          return <pre style={preCss}>{rowData.releaseNote}</pre>;
        }}

What I want to know is:

Is it possible to also make the "search" function search against data in the "detail panel". If yes, how ?

3 Answers 3

3

For anyone having same issue, I believe I found a workaround. I added the "rowData.releaseNote" as a column entry in main table. But then I zeroed out the headerStyle and cellStyle widths and set display:none. So essentially, the data exists as an invisible column in the table.

 {
    title: "",
    field: "releaseNote",
    sorting: false,
    filtering: false,
    headerStyle: { display: "none", width: "0px", maxWidth: "0px" },

    cellStyle: { display: "none", width: "0px", maxWidth: "0px" }
  }
2
  • Where do you add this piece of code? Inside the detailPanel property of the MaterialTable?
    – L H
    Commented Aug 26, 2020 at 7:30
  • @LH No, I think he added it columns array which is passed as a prop to Material Table component Commented Nov 23, 2021 at 11:19
2

Wai Ha Lee's solution will cause weird spacing in Columns in my Material-table, I use this one to solve the problem:

      {
        title: "",
        field: "releaseNote",
        sorting: false,
        filtering: false,
        hidden: true,
        searchable: true,
        width: "0px"
      }
0
-2

Adding:

{ 
   hidden: true,
}

should work.

1
  • If it's a duplicate, it is not an obvious one. The other answer has a lot more code, and does not highlight that the important/essential part of the solution is just the hidden rule. This answer implies that "hidden" is the only piece needed to solve the issue. That said, it could benefit from an explanation. Code only answers are discouraged. Commented Oct 20, 2020 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.