material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Columns that are unhidden from remote data not displaying filter input?

Open calebhypes opened this issue 7 years ago • 4 comments

I've got a table that's using the data=query function to grab remote data, this query is also grabbing parameters (vary in amount based on user inputs) and turning these parameters into hidden columns. When one of these additional columns is unhidden, the filter input is not being displayed below the column name.

Table Query Code

data={query =>
            new Promise((resolve, reject) => {
              fetch(url, {
                headers: {
                  // update current page and pageSize on pagination
                  Range:
                    "items=" +
                    query.pageSize * query.page +
                    "-" +
                    (query.pageSize * (query.page + 1) - 1)
                }
              })
                .then(response => {
                  // grab total amount of items from response content range
                  let contentRange = response.headers.get("Content-Range");
                  let itemTotal = parseInt(
                    contentRange.match(/[^items *\-*/].+/g)
                  );
                  this.setState({ rowTotal: itemTotal });
                  return response.json();
                })
                .then(result => {
                  // grab first item in results (all items will have the same entity parameters, no need to iterate over each result item)
                  let item = result[0];
                  // iterate over each entity parameter to ensure we grab all of them
                  item.entityParam.forEach(param => {
                    // create new column for each entity parameter, set column title, field data using render, and hidden to true.
                    let newColumn = {
                      title: param.inputLabel,
                      render: rowData =>
                        rowData.entityParam.find(
                          x => x.inputLabel === param.inputLabel
                        ).displayValue,
                      hidden: true
                    };
                    // check that the column doesn't already exist to avoid duplicate column listings.
                    const found = this.state.columns.some(
                      el => el.title === newColumn.title
                    );
                    if (!found) {
                      this.setState({
                        columns: [...this.state.columns, newColumn]
                      });
                    }
                  });
                  resolve({
                    data: result,
                    page: query.page,
                    totalCount: this.state.rowTotal
                  });
                });
            })
          }

This is setting up all of our hidden columns in the show/hide and rendering the data to the row properly but not displaying the filter input as shown below:

Show/Hide Columns Displaying Properly showhide

No Filter on Added Column nofilter

calebhypes avatar Mar 29 '19 16:03 calebhypes

Hi @CalebCox,

You didn't add 'field' to your newColumn. So material-table does not know how to filter or search on this area. You should add a field area or add a customFilterAndSearch function to column.

mbrn avatar Mar 30 '19 15:03 mbrn

@mbrn Thank you for the response! I didn't see the 'field' used in the remote data example in the documentation so that never crossed my mind!

Regarding that 'field' value, the field I need is in an object, nested inside of another object which is part of an array of objects being returned from the fetch, I know the 'field' expects a string, is there any way to do dot notation to drill down the the level/index I need for that key value?

calebhypes avatar Apr 01 '19 15:04 calebhypes

You can use this kind of field: 'names.surname'

I guess that you asked for this?

mbrn avatar Apr 01 '19 19:04 mbrn

@mbrn , apologies for the late follow up, this appears to have worked! Thank you!

field: `${param.paramName}`

calebhypes avatar Apr 04 '19 14:04 calebhypes