Mui-datatables: Any option to submit filter on 'Enter key press'?

Created on 4 Nov 2020  路  2Comments  路  Source: gregnb/mui-datatables


I am using confirmFilters=true. Right now, customFilterDialogFooter has a button which apply the filters with onClick event however i also want to apply the filters if the user press enter key

Most helpful comment

Try this.

useEffect(() => {
    const ALLOWED_KEYS = ['Enter'] // ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']
    const handleKeyDown = event => {
      const { key } = event
      if (ALLOWED_KEYS.includes(key)) {
        const applyButton = document.getElementById('<ID-OF-YOUR-BUTTON-HERE>')
        if (applyButton) applyButton.click()
      }
    }

    document.addEventListener('keydown', handleKeyDown)

    return () => {
      document.removeEventListener('keydown', handleKeyDown)
    }
  }, [])

All 2 comments

Try this.

useEffect(() => {
    const ALLOWED_KEYS = ['Enter'] // ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']
    const handleKeyDown = event => {
      const { key } = event
      if (ALLOWED_KEYS.includes(key)) {
        const applyButton = document.getElementById('<ID-OF-YOUR-BUTTON-HERE>')
        if (applyButton) applyButton.click()
      }
    }

    document.addEventListener('keydown', handleKeyDown)

    return () => {
      document.removeEventListener('keydown', handleKeyDown)
    }
  }, [])

Try this.

useEffect(() => {
    const ALLOWED_KEYS = ['Enter'] // ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']
    const handleKeyDown = event => {
      const { key } = event
      if (ALLOWED_KEYS.includes(key)) {
        const applyButton = document.getElementById('<ID-OF-YOUR-BUTTON-HERE>')
        if (applyButton) applyButton.click()
      }
    }

    document.addEventListener('keydown', handleKeyDown)

    return () => {
      document.removeEventListener('keydown', handleKeyDown)
    }
  }, [])

my guy!!! thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

T-pirithiviraj picture T-pirithiviraj  路  3Comments

gangakrishh picture gangakrishh  路  3Comments

chapmanjacobd picture chapmanjacobd  路  4Comments

naothomachida picture naothomachida  路  3Comments

harryluo91 picture harryluo91  路  3Comments