ttk-app-core
Version:
enterprise develop framework
77 lines (71 loc) • 3.39 kB
JavaScript
import React from 'react'
import { Menu, Checkbox, DataGrid,Icon, TableSort } from 'edf-component'
//let centerArr = ['seq'],
//rightArr = ['origValueStr', 'accuDepreciationStr','yearPeriodDepreciationStr','queryPeriodDepreciationStr', 'netWorthStr']
export default function renderGridColumns(columnNameList, list, other, fun, sortChange) {
const arr = []
const res = columnNameList.map((element,index) => {
return (
element.isVisible ?
<DataGrid.Column
name = {element.fieldName}
columnKey={element.fieldName}
isResizable={true}
header={element.isOrderMode ? <DataGrid.Cell>{element.caption}<TableSort sortOrder={other.sort.userOrderField == element.fieldName ? other.sort.order : null} handleClick={(e) => {sortChange(element.fieldName, e)}}></TableSort></DataGrid.Cell> : <DataGrid.Cell>{element.caption}</DataGrid.Cell>}
cell={({rowIndex, ...props}) => {
return <DataGrid.Cell {...props} tip={true} className={getClassName(list[rowIndex], element.idAlignType)}>
{list[rowIndex] && list[rowIndex][element.fieldName] ?
((element.idFieldType == '1000040002' && Number(list[rowIndex][element.fieldName])) ? (addThousandsPosition(list[rowIndex][element.fieldName])) : list[rowIndex][element.fieldName]) : ''}
</DataGrid.Cell>
}}
width={element.width}
/> : null
)})
res.push(<DataGrid.Column
name = 'option'
columnKey='option'
fixedRight= {true}
header={<DataGrid.Cell style = {{position: 'relative'}}>
<Icon style = {{position: 'absolute', left: 0}} type='youcezhankailanmushezhi' fontFamily='edficon' onClick={() => fun({value:true})}/>
</DataGrid.Cell>}
cell={({rowIndex, ...props}) => {
return <DataGrid.Cell {...props} className={rowIndex == list.length - 1 ? 'total rightName' : ''}>
</DataGrid.Cell>
}}
width={30}
/>)
res.push(<DataGrid.Column
name = 'option'
columnKey='option'
flexGrow={1}
header={<DataGrid.Cell></DataGrid.Cell>}
cell={({rowIndex, ...props}) => {
return <DataGrid.Cell {...props} className={rowIndex == list.length - 1 ? 'total rightName' : ''}>
</DataGrid.Cell>}} width={0}
/>)
return res
}
function getClassName(option, idAlignType){
let leftName = 'mk-datagrid-cellContent-left',
rightName = 'mk-datagrid-cellContent-right'
if(idAlignType == '1000050002'){
return !Number(option.seq) ? 'total':''
}else if(idAlignType == '1000050003'){
return !Number(option.seq) ? `total ${rightName}`:rightName
}else{
return !Number(option.seq) ? `total ${leftName}`:leftName
}
}
function addThousandsPosition(value){
let num
if(value == 0){
return parseFloat(0).toFixed(2)
}
if (value != '') {
num = parseFloat(value).toFixed(2)
}else{
num = value.toString()
}
let regex = /(\d{1,3})(?=(\d{3})+(?:\.))/g
return num.replace(regex, "$1,")
}