search-ui icon indicating copy to clipboard operation
search-ui copied to clipboard

How to customize how a filter value is rendered?

Open ZakKa89 opened this issue 2 years ago • 10 comments

I want to be able to customize how a value is rendered for a type: "value" filter. Is this possible? I've only seen this possible for the 'range' type where you can render a value for a specific range. But what I want is a lot simpler:

Why this is a problem

Sometimes the data you work with just doesn't have human readable friendly values, for example:

image

Example of what I'm looking for

<Facet renderValue={(value) => value.toLowerCase() } />

Or something similar in the config is also fine.

Example implementation in MUI

Other popular component libraries have something like this in the api like 'renderValue' in the select component of MUI renderValue in MUII API

ZakKa89 avatar Mar 22 '23 21:03 ZakKa89

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar May 22 '23 13:05 botelastic[bot]

The issue is still very important, imo this is a must have for any frontend library/package. Almost no frontend would render the raw data from a backend without mapping/transforming.

ZakKa89 avatar May 23 '23 13:05 ZakKa89

@ZakKa89 I assume you're using react so does this help?

<Facet field={"Name"} label="Name" view={CustomFacet} />

const CustomFacet = ({
  label,
  options,
  onRemove,
  onSelect,
  onSearch,
  showSearch,
  searchPlaceholder,
  showMore,
  onMoreClick,
}: FacetViewProps) => {
  return (
    <>
      <p>{label}</p>
      <div>
        {options.length < 1 && <p>No matching options</p>}
        {options.map(op => (
          <Checkbox
            fullWidth
            // This is what you're looking for
            label={op.value.toLowerCase()}
            onChange={() =>
              op.selected
                ? onRemove(op.value as FieldValue)
                : onSelect(op.value as FieldValue)
            }
            state={op.selected ? "selected" : "unselected"}
          />
        ))}
      </div>
    </>
  );
};

omonk avatar Jul 21 '23 09:07 omonk

@omonk Thanks ! Will try that out. I think the issue should remain open because I think the library should support this without the need to render a complete custom facet.

ZakKa89 avatar Jul 23 '23 12:07 ZakKa89

@ZakKa89 for sure, trouble with rewriting the value that is rendered is that it'll screw up the filters but there should be an option to augment what is visually rendered

omonk avatar Jul 23 '23 21:07 omonk

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar Sep 21 '23 21:09 botelastic[bot]

Nah, don't mark as stale. Feature request still stands.

ZakKa89 avatar Sep 27 '23 06:09 ZakKa89

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar Nov 26 '23 07:11 botelastic[bot]

Nah, don't mark as stale. Feature request still stands.

ZakKa89 avatar Dec 02 '23 17:12 ZakKa89

Thanks il put this on a list of improvements. For now developers can override the view component for this.

joemcelroy avatar Jan 26 '24 10:01 joemcelroy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

botelastic[bot] avatar Mar 26 '24 14:03 botelastic[bot]

bad bot

ZakKa89 avatar Apr 05 '24 10:04 ZakKa89