Browse Source

테이블 클릭 이벤트 분기 처리

master
sanguu516 3 months ago
parent
commit
4922b5c020
  1. 54
      src/components/flight/NewFlightApprovalsTable.js

54
src/components/flight/NewFlightApprovalsTable.js

@ -21,10 +21,13 @@ export default function NewFlightApprovalsTable(props) {
// 확장된 행 키 // 확장된 행 키
const [expandedRowKeys, setExpandedRowKeys] = useState([]); const [expandedRowKeys, setExpandedRowKeys] = useState([]);
// 수정 키
const [editingKey, setEditingKey] = useState(''); const [editingKey, setEditingKey] = useState('');
const [form] = Form.useForm(); const [form] = Form.useForm();
// 수정 키 확인
const isEditing = record => record.key === editingKey; const isEditing = record => record.key === editingKey;
// 승인, 미승인, 비대상 건수 계산 // 승인, 미승인, 비대상 건수 계산
@ -32,6 +35,7 @@ export default function NewFlightApprovalsTable(props) {
resApprovalCd(); resApprovalCd();
}, [laancAprvList]); }, [laancAprvList]);
// 수정 이벤트
const edit = record => { const edit = record => {
form.setFieldsValue({ form.setFieldsValue({
bufferZone: '', bufferZone: '',
@ -42,10 +46,12 @@ export default function NewFlightApprovalsTable(props) {
setEditingKey(record.key); setEditingKey(record.key);
}; };
// 취소 이벤트
const cancel = () => { const cancel = () => {
setEditingKey(''); setEditingKey('');
}; };
// 저장 이벤트
const save = async key => { const save = async key => {
try { try {
const row = await form.validateFields(); const row = await form.validateFields();
@ -67,6 +73,7 @@ export default function NewFlightApprovalsTable(props) {
} }
}; };
// 데이터
const columns = [ const columns = [
{ {
title: ( title: (
@ -369,6 +376,7 @@ export default function NewFlightApprovalsTable(props) {
} }
]; ];
// 확장된 테이블 데이터
const expandedRowRender = record => { const expandedRowRender = record => {
const childColumns = [ const childColumns = [
{ {
@ -513,8 +521,16 @@ export default function NewFlightApprovalsTable(props) {
dataSource={data} dataSource={data}
pagination={false} pagination={false}
onRow={record => ({ onRow={record => ({
onClick: () => { onClick: event => {
handleInRowClick(record); // 이벤트 버블링을 막기 위해 클릭된 요소가 'Edit' 버튼인지 확인
if (
event.target.tagName !== 'BUTTON' &&
event.target.tagName !== 'A' &&
!event.target.closest('.ant-input') && // input 요소를 감지
!event.target.closest('.ant-input-number') // inputNumber 요소를 감지
) {
handleInRowClick(record);
}
} }
})} })}
showHeader={false} showHeader={false}
@ -524,6 +540,7 @@ export default function NewFlightApprovalsTable(props) {
); );
}; };
// 테이블 데이터
const mergedColumns = columns.map(col => { const mergedColumns = columns.map(col => {
if (!col.editable) { if (!col.editable) {
return col; return col;
@ -574,14 +591,6 @@ export default function NewFlightApprovalsTable(props) {
} }
}; };
// 테이블 내부 행 클릭 이벤트
const handleInRowClick = row => {
console.log('>>', row);
handlerOpenModal(row.approvalCd, row.fltElev, row.fltElevMax);
props.handlerDetail(row);
};
// 날짜 포맷 변경 // 날짜 포맷 변경
const formatDate = dateString => { const formatDate = dateString => {
const date = new Date(dateString); const date = new Date(dateString);
@ -614,6 +623,7 @@ export default function NewFlightApprovalsTable(props) {
}); });
}; };
//
const handleExpand = key => { const handleExpand = key => {
const expanded = expandedRowKeys.includes(key); const expanded = expandedRowKeys.includes(key);
const keys = expanded const keys = expanded
@ -633,6 +643,14 @@ export default function NewFlightApprovalsTable(props) {
props.handlerDetail(row.areaList[0]); props.handlerDetail(row.areaList[0]);
}; };
// 확장된 테이블 행 클릭 이벤트
const handleInRowClick = row => {
console.log('>>', row);
handlerOpenModal(row.approvalCd, row.fltElev, row.fltElevMax);
props.handlerDetail(row);
};
return ( return (
<div className='layer-content'> <div className='layer-content'>
<div className='layer-ti d-flex justify-content-between align-items-center'> <div className='layer-ti d-flex justify-content-between align-items-center'>
@ -679,6 +697,8 @@ export default function NewFlightApprovalsTable(props) {
...item, ...item,
key: index key: index
}))} }))}
테이블
데이터
columns={mergedColumns} columns={mergedColumns}
rowClassName={record => { rowClassName={record => {
let className = ''; let className = '';
@ -692,8 +712,16 @@ export default function NewFlightApprovalsTable(props) {
}} }}
pagination={false} pagination={false}
onRow={record => ({ onRow={record => ({
onClick: () => { onClick: event => {
handleRowClick(record); // 이벤트 버블링을 막기 위해 클릭된 요소가 'Edit' 버튼인지 확인
if (
event.target.tagName !== 'BUTTON' &&
event.target.tagName !== 'A' &&
!event.target.closest('.ant-input') && // input 요소를 감지
!event.target.closest('.ant-input-number') // inputNumber 요소를 감지
) {
handleRowClick(record);
}
} }
})} })}
expandable={{ expandable={{
@ -746,7 +774,7 @@ const EditableCell = ({
rules={[ rules={[
{ {
required: true, required: true,
message: `Please Input ${title}!` message: `값을 입력 해 주세요.`
} }
]} ]}
> >

Loading…
Cancel
Save