Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Commit

Permalink
moved test bugfix editor
Browse files Browse the repository at this point in the history
  • Loading branch information
sajrashid committed Jul 23, 2021
1 parent 6ea3a0b commit 65f9a4c
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 35 deletions.
4 changes: 1 addition & 3 deletions src/components/react-dj-table/children/cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const Cells=({ state,dispatch, row, editable})=>{
const dateOptions = options.dateOptions || {}
const readOnly = options.readOnly || []
const columns = Object.keys(row)
console.log(readOnly)

const onChange = (e) => {

var item = e.currentTarget.name.toString();
Expand All @@ -55,7 +53,7 @@ const Cells=({ state,dispatch, row, editable})=>{
const editcssClasses = `editInputText ${styles}`
const isReadOnly = _.includes(readOnly, key)
if(isHidden) return null
if (isReadOnly) return <td className={editcssClasses} key={key}> <input name={key} readonly disabled type="text" value={row[key].toString()}></input> </td>
if (isReadOnly) return <td className={editcssClasses} key={key}> <input name={key} readOnly disabled type="text" value={row[key].toString()}></input> </td>
if(isCheckBox && options.checkBox !== false) return <td type="checkbox" className={cssClasses} key={key}> <input name={key} onChange={onChange} type='checkbox' checked={row[key]}></input></td>
if(isCustom ) return <td className={editcssClasses} key={key}><input type="text" name={key} onChange={onChange} value={row[key].toString()}></input> </td>
if(isDateCol) return <td className={editcssClasses} key={key}> <input type="text" name={key} onChange={onChange} value={row[key].toString()}></input> </td>
Expand Down
16 changes: 11 additions & 5 deletions src/components/react-dj-table/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useReducer } from 'react'

import { ACTIONS } from './reducers/actions'
import Crud from './children/crud'
import GlobalSearch from './children/globalsearch'
import Pager from './children/pager'
import PropTypes from "prop-types"
import Rows from './children/rows'
import { TableReducer } from '../react-dj-table/reducers/tableReducer'
import { TableReducer } from './reducers/tableReducer'
import Thead from './children/thead'
import { createMarkup } from '../react-dj-table/utils/utils'
import { createMarkup } from './utils/utils'

const Table = (props) => {
// setup initial state
Expand Down Expand Up @@ -38,16 +39,21 @@ const Table = (props) => {
if (pageable) {
json = paginate(json || [], pageSize, 0)
}

const crudBtns= {btnCancel:true, btnUpdate:true, btnCreate:false, btnInsert:true, btnDelete:true }

const initialState = {
json: json, jsonCopy: props.json, options: options, pageable: pageable, selectedRow: {}, selectedRowCopy: null, selectedRowCss: selectedRowCss,
sortDirection: sortDirection, pagerInput: pagerInput, pageSize: pageSize, pageSizeCopy: pageSize, totalPages: totalPages,
crudBtns:crudBtns , dataChanged:false, inserting: false, userAction:'NOACTION',creating: false, editing: true, pageNo: pageNo, pagerIcons: pagerIcons, searchString: ''
colspan: colspan, insertId: null, crudBtns:crudBtns , dataChanged:false, inserting: false, userAction:'NOACTION',creating: false, editing: true, pageNo: pageNo, pagerIcons: pagerIcons, searchString: ''
}
const [state, dispatch] = useReducer(TableReducer, initialState)

React.useEffect(() => {
console.log("props:", props)
dispatch({type: ACTIONS.UPDATEPROPS, payload: { updatedProps: props }})
},[props])


const [state, dispatch] = useReducer(TableReducer, initialState)
const styles = options.tableCss || ''
const cssClasses = ` ${styles}`
const pagerCss = options.pagerCss || ''
Expand Down
2 changes: 1 addition & 1 deletion src/components/react-dj-table/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dj-table",
"version": "1.1.0",
"version": "1.1.2",
"description": "React Dynamic Resposive Json HTML Table",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/components/react-dj-table/reducers/actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const ACTIONS={
INITIALSTATE:'initialState',
UPDATEPROPS:'updateprops',
SELECTEDROW:'selectedRow',
CREATESELECTEDROWCOPY:'CreateSelectedRowCopy',
CONFIRMDELETE:'confirmdelete',
Expand Down
13 changes: 12 additions & 1 deletion src/components/react-dj-table/reducers/tableReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export const TableReducer = (state, action) => {
state.pageable = action.payload.pageable
action.payload.pageable ? state.json = paginate(state.json || [], state.pageSize, 0) : state.totalPages = (Math.ceil(state.json.length / state.pageSize))
return { ...state }
case ACTIONS.UPDATEPROPS:
state.json = action.payload.updatedProps.json
state.options.pageable ? state.json = paginate(state.json || [], state.pageSize, 0) : state.totalPages = (Math.ceil(state.json.length / state.pageSize))
state.jsonCopy = state.json
return { ...state }
case ACTIONS.ITEMSPERPAGE:
state.pageSize = action.payload.itemsPerPage
state.totalPages = Math.ceil(state.jsonCopy.length / state.pageSize)
Expand Down Expand Up @@ -260,10 +265,16 @@ export const TableReducer = (state, action) => {
state.json = (paginate(state.jsonCopy, state.pageSize, state.pageNo - 1))
return { ...state }
case ACTIONS.CONFIRMINSERT:
state.selectedRow = {}
const idColIdx = state.options.idCol ? Object.keys(state.json[0]).indexOf(state.options.idCol) : 0
console.log(idColIdx)
if(action!==undefined && action.payload !==undefined){
if(action.payload.id!==undefined) state.selectedRow[idColIdx]=action.payload.id
}
console.log(state.selectedRow[idColIdx])
state.selectedRowCopy = {}
state.crudBtns.btnCancel=true
state.crudBtns.btnInsert=true
state.selectedRow = {}
state.userAction = 'CONFIRMINSERT'
return { ...state }
case ACTIONS.RETURNSTATE:
Expand Down
Loading

0 comments on commit 65f9a4c

Please sign in to comment.