TIL

[TIL] 20211207 react-table editable/ fixed column/ css

자바칩 프라푸치노 2021. 12. 10. 16:04

1. react table editable 

https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/editable-data

 

tannerlinsley/react-table: editable-data - CodeSandbox

tannerlinsley/react-table: editable-data using namor, react, react-dom, react-scripts, react-table, styled-components

codesandbox.io

https://react-table.tanstack.com/docs/examples/editable-data

 

Examples: Editable Data

Subscribe to our newsletter The latest TanStack news, articles, and resources, sent to your inbox.

react-table.tanstack.com

 

 

2. react input focus blur event

const inputRef = useRef();

const handleKeyPress = (e) => {
    if(e.key === 'Enter') {
      console.log('enter')
      inputRef.current.blur();
    }
  }

return <input 
            value={value} 
            onChange={onChange} 
            onBlur={onBlur} 
            css={inputStyle}
            onKeyPress={handleKeyPress}
            ref={inputRef}
            />

 

 

3. react-table fixed column

http://www.recompile.in/2019/11/react-fixed-table-header-code-without.html

https://codesandbox.io/s/react-table-fixed-columns-official-kowzlm5jp7

https://gojjc.tistory.com/entry/reactReact-Table-지정-컬럼-고정시키하기

 

[React] React-Table 지정 컬럼 고정시키하기

React-Table에서 컬럼을 고정하는 방법을 공유합니다. 1. 우선react-table-hoc-fixed-columns react 모듈 을 설치한다.  참조: https://www.npmjs.com/package/react-table-hoc-fixed-columns npm install rea..

gojjc.tistory.com

 

 

4. table view 에 border넣기

https://www.codingfactory.net/10510

 

CSS / 표(table) 꾸미기 / 테두리 만들기

테두리 만드는 속성 테두리는 border 속성으로 만듭니다. table, th, td 요소에 적용할 수 있습니다. tr 요소에는 적용되지 않습니다. 기본 모양 아무런 꾸밈을 하지 않았다면 기본 모양은 테두리가 없

www.codingfactory.net

 

 

5. editable table에서 input타입을 동적으로 렌더링 하고 싶음

// import makeData from './makeData'
const EditableCell = ({
  value : initialValue,
  row : {index},
  column : {id},
  updateMyData,
}) => {
  const [value, setValue ] = useState(initialValue);
  const [type, setType] = useState('type');
  const inputRef = useRef();
  const onChange = e => {
      setValue(e.target.value);
  }
  const onBlur = () => {
    updateMyData()
  }
  const handleKeyPress = (e) => {
    if(e.key === 'Enter') {
      inputRef.current.blur();
    }
  }
  useEffect(()=>{
      setValue(initialValue)
      setType(typeof value)
  },[initialValue])

  return <input 
            value={value} 
            onChange={onChange} 
            onBlur={onBlur} 
            css={inputStyle}
            onKeyPress={handleKeyPress}
            ref={inputRef}
            type={type}
            />
}
728x90