修改序号渲染方式,排序新增stringChinese类型

This commit is contained in:
huayj 2019-08-28 10:47:27 +08:00
parent ee1ec1c558
commit 5073e7f5fd
3 changed files with 51 additions and 21 deletions

View File

@ -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);

View File

@ -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];

View File

@ -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 = [];