Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeTable/Tree: filtering should use content of TreeNode.data (if defined) #7460

Open
nimo23 opened this issue Dec 1, 2024 · 3 comments
Open
Labels
Status: Discussion Issue or pull request needs to be discussed by Core Team

Comments

@nimo23
Copy link

nimo23 commented Dec 1, 2024

Describe the bug

Defining a TreeNode for TreeTable (or Tree) as follows:

const userNode: TreeNode = {
    key: user.id,
    label: user.username,
    data: {
        name: (
        <div>
            <i className="pi pi-user pr-2"></i>
            <span>{user.username}</span>
        </div>
    ),
..

with column:

<Column field="name" header="" expander>

will render the Tree correctly. However, when having custom jsx in the data.name field, the TreeTable.globalFilter does not work anymore.

The filtering works when using a TreeNode without custom jsx:

const userNode: TreeNode = {
    key: user.id,
    label: user.username,
    data: {
        name: user.username,
..

Reproducer

No response

System Information

primereact 10.8.3

Steps to reproduce the behavior

  1. Setup a TreeTable (or Tree) with a TreeNode like above
  2. Add globalFilter to TreeTable (with state-hook) and input field:

<InputText type="search" placeholder="Search" onChange={e => setGlobalFilter(e.target.value)} />

  1. Test the filter.

Expected behavior

The filtering should filter the content of TreeNode.data-fields.

@nimo23 nimo23 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 1, 2024
@nimo23 nimo23 changed the title TreeTable/Tree: filtering should always use TreeNode.label (if explicitly defined) TreeTable/Tree: filtering should use content of TreeNode.data (if defined) Dec 1, 2024
@nimo23
Copy link
Author

nimo23 commented Dec 1, 2024

I also tried it by setting a custom filter (with <TreeTable filters={customFilter} ..>) to configure the global filter. But it does not work.

const customFilter: TreeTableFilterMeta = {
	  global: {
	    value: 'label', // value: 'name' does also not work
	    matchMode: FilterMatchMode.STARTS_WITH
	  }
	};

@nimo23
Copy link
Author

nimo23 commented Dec 1, 2024

Adding a non global filter does also not work:

<Column field="name" header="" filter expander>

I guess the reason filtering doesn't work in this case is that Primereact doesn't escape the HTML tags (defined as a template inside data.name) when filtering.

@melloware
Copy link
Member

Most likely it doesn't escape them to prevent XSS.

@melloware melloware added Status: Discussion Issue or pull request needs to be discussed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Discussion Issue or pull request needs to be discussed by Core Team
Projects
None yet
Development

No branches or pull requests

2 participants