Record Search Box in GridField - Searching Names (First and Last)

As far as I know, the record search box on a record-backed gridField will do a search on the raw data of all of the columns in the grid. For example, searching for "username1" will return any rows that contain "username1" in any of the columns' raw data, regardless of how the data is formatted. If the column data was formatted to show First Name or Last Name, a search for "username1" would still return the row; however a search for the First Name value or Last Name value would not return any results, as this is a formatted value and not the raw value.

I have a requirement for the search box to enable searching on first name and last name values, not only username. Are there any elegant solutions to enable this?

The only ideas I have are not very elegant:

  1. create a daily username sync process so the database has the user's first and last names, then update the view / cdt to include these values.
  2. convert the record to an expression backed record and construct the datasubset with the first name and last name values

  Discussion posts and replies are publicly visible

Parents
  • You could make your own custom search box bound to a local variable, and then filter the grid based on that variable, like so:

    {
      a!localVariables(
        local!search:"",
      a!boxLayout(
        label:"users",
        contents:{
          a!textField(
            label: "",
            labelPosition: "ABOVE",
            placeholder: "Search Users",
            value: local!search,
            saveInto: local!search,
            refreshAfter: "UNFOCUS",
            validations: {}
          ),
      a!gridField(
        label: "Read-only Grid",
        labelPosition: "COLLAPSED",
        data: a!recordData(
          recordType: 'recordType!{SYSTEM_RECORD_TYPE_USER}User',
          filters: a!queryLogicalExpression(
            operator: "OR",
            filters: {
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username',
                operator: "includes",
                value: local!search
              ),
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{firstName}firstName',
                operator: "includes",
                value: local!search
              ),
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{lastName}lastName',
                operator: "includes",
                value: local!search
              ),
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email',
                operator: "includes",
                value: local!search
              )
            },
            ignoreFiltersWithEmptyValues: true
          )
        ),
        columns: {
          a!gridColumn(
            label: "user",
            sortField: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username',
            value: fv!row['recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username']
          ),
          a!gridColumn(
            label: "email",
            sortField: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email',
            value: fv!row['recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email'],
            align: "START"
          )
        },
        validations: {},
        showSearchBox: false,
        showRefreshButton: false
    )
        }))}
    

Reply
  • You could make your own custom search box bound to a local variable, and then filter the grid based on that variable, like so:

    {
      a!localVariables(
        local!search:"",
      a!boxLayout(
        label:"users",
        contents:{
          a!textField(
            label: "",
            labelPosition: "ABOVE",
            placeholder: "Search Users",
            value: local!search,
            saveInto: local!search,
            refreshAfter: "UNFOCUS",
            validations: {}
          ),
      a!gridField(
        label: "Read-only Grid",
        labelPosition: "COLLAPSED",
        data: a!recordData(
          recordType: 'recordType!{SYSTEM_RECORD_TYPE_USER}User',
          filters: a!queryLogicalExpression(
            operator: "OR",
            filters: {
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username',
                operator: "includes",
                value: local!search
              ),
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{firstName}firstName',
                operator: "includes",
                value: local!search
              ),
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{lastName}lastName',
                operator: "includes",
                value: local!search
              ),
              a!queryFilter(
                field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email',
                operator: "includes",
                value: local!search
              )
            },
            ignoreFiltersWithEmptyValues: true
          )
        ),
        columns: {
          a!gridColumn(
            label: "user",
            sortField: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username',
            value: fv!row['recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{username}username']
          ),
          a!gridColumn(
            label: "email",
            sortField: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email',
            value: fv!row['recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{email}email'],
            align: "START"
          )
        },
        validations: {},
        showSearchBox: false,
        showRefreshButton: false
    )
        }))}
    

Children