diff --git a/src/ColumnManager.js b/src/ColumnManager.js index f1bfbf7..bf9c41d 100644 --- a/src/ColumnManager.js +++ b/src/ColumnManager.js @@ -35,12 +35,24 @@ export default class ColumnManager { if(!showRowNum){ return columns } + let { key, fixed, width, name, type, base } = showRowNum; let order = { - dataIndex: showRowNum.key || '_index', + dataIndex: key || '_index', key:'_index', - fixed:showRowNum.fixed || 'left', - width:showRowNum.width || 50, - title: showRowNum.name || '序号', + fixed:fixed || 'left', + width:width || 50, + title: name || '序号', + render:(text, record, index)=>{ + switch( type ){ + case 'ascii':{ + return (String.fromCharCode((base || 'a').charCodeAt()) + index); + } + case 'number': + default:{ + return ( (base || 0) + index); + } + } + } } if(columns.length > 0 && columns[0].dataIndex !== 'checkbox' && columns[0].dataIndex !== 'radio'){ // 多选表格/单选表格时放在第二列,其他情况放到第一列 columns = [order].concat(columns); diff --git a/src/Table.js b/src/Table.js index 42d6e0a..a27acc9 100644 --- a/src/Table.js +++ b/src/Table.js @@ -691,23 +691,23 @@ class Table extends Component { const lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ?props.lazyLoad.endIndex :-1; for (let i = 0; i < data.length; i++) { let isHiddenExpandIcon; - if ( props.showRowNum ){ - switch(props.showRowNum.type){ - case 'number':{ - data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i; - break; - } - case 'ascii': { - data[i][props.showRowNum.key || '_index'] = String.fromCharCode(i + (props.showRowNum.base || '0').charCodeAt()); - break; - } - default: { - data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i; - break; - } - } + // if ( props.showRowNum ){ + // switch(props.showRowNum.type){ + // case 'number':{ + // data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i; + // break; + // } + // case 'ascii': { + // data[i][props.showRowNum.key || '_index'] = String.fromCharCode(i + (props.showRowNum.base || '0').charCodeAt()); + // break; + // } + // default: { + // data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i; + // break; + // } + // } - } + // } const record = data[i]; const key = this.getRowKey(record, i); const childrenColumn = record[childrenColumnName]; diff --git a/src/lib/sort.js b/src/lib/sort.js index 62fe5de..1e4a4bf 100644 --- a/src/lib/sort.js +++ b/src/lib/sort.js @@ -249,7 +249,20 @@ export default function sort(Table, Icon) { if (column.sorter || column.sortEnable ) { //大于0说明不是升序就是降序,判断orderNum有没有值,没有值赋值 if ( column.sortEnable && !column.sorter) { - column.sorter = column.fieldType === 'number' ? this.numberSortFn(column.dataIndex) : this.defaultSortFn(column.dataIndex); + switch(column.fieldType){ + case 'number':{ + column.sorter = this.numberSortFn(column.dataIndex); + break; + } + case 'stringChinese':{ + column.sorter = this.chineseSortFn(column.dataIndex); + break; + } + default:{ + column.sorter = this.defaultSortFn(column.dataIndex); + break; + } + } } if (iconTypeIndex > 0 && !column.orderNum && mode == "multiple") { column.orderNum = this.getOrderNum(); @@ -286,6 +299,11 @@ export default function sort(Table, Icon) { return numberA >= numberB ? 1 : -1; } + // 中文比较函数,按拼音排序 + chineseSortFn = (key) => (a, b)=>{ + return a[key].localeCompare(b[key], 'zh-Hans-CN',{sensitivity: 'accent'}); + } + _flatToColumn(flatColumns){ const colLen = flatColumns.length; let parentIndex,rsColumns = [];