fix sort and filter

This commit is contained in:
afc163 2015-08-12 12:47:04 +08:00
parent fb5632b61b
commit dfff7ef86b
2 changed files with 32 additions and 11 deletions

View File

@ -27,7 +27,7 @@ var FilterMenu = React.createClass({
handleClearFilters() {
this.setState({
selectedKeys: []
});
}, this.handleConfirm);
},
handleConfirm(){
this.props.confirmFilter(this.props.column, this.state.selectedKeys);

View File

@ -15,10 +15,6 @@ function defaultResolve(data) {
return data || [];
}
function getColumnKey(col, index) {
return col.key || col.dataIndex || index;
}
class DataSource {
init(config) {
this.config = config;
@ -117,6 +113,19 @@ var AntTable = React.createClass({
let sortColumn = this.state.sortColumn;
let sortOrder = this.state.sortOrder;
let sorter;
//
let isSortColumn = this.isSortColumn(column);
if (!isSortColumn) { //
sortOrder = order;
sortColumn = column;
} else { //
if (sortOrder === order) { //
sortOrder = '';
sortColumn = null;
} else { //
sortOrder = order;
}
}
if (this.isLocalDataSource()) {
sorter = function () {
let result = column.sorter.apply(this, arguments);
@ -243,14 +252,23 @@ var AntTable = React.createClass({
return this.isLocalDataSource() ? this.getLocalDataPaging() : this.state.data;
},
getColumnKey(column) {
return column.key || column.dataIndex;
getColumnKey(column, index) {
return column.key || column.dataIndex || index;
},
isSortColumn(column) {
if (!column || !this.state.sortColumn) {
return false;
}
let colKey = this.getColumnKey(column);
let isSortColumn = (this.getColumnKey(this.state.sortColumn) === colKey);
return isSortColumn;
},
renderColumnsDropdown(columns) {
return columns.map((column, i) => {
column = objectAssign({}, column);
let key = this.getColumnKey(column);
let key = this.getColumnKey(column, i);
let filterDropdown, menus, sortButton;
if (column.filters && column.filters.length > 0) {
let colFilters = this.state.filters[key] || [];
@ -267,11 +285,14 @@ var AntTable = React.createClass({
</Dropdown>;
}
if (column.sorter) {
var colKey = getColumnKey(column, i);
let isSortColumn = (getColumnKey(this.state.sortColumn, i) === colKey);
let isSortColumn = this.isSortColumn(column);
if (isSortColumn) {
column.className = column.className || '';
column.className += ' ant-table-column-sort';
if (this.state.sortOrder) {
column.className += ' ant-table-column-sort';
} else {
column.className = column.className.replace(' ant-table-column-sort', '');
}
}
sortButton = <div className="ant-table-column-sorter">
<span className={'ant-table-column-sorter-up ' +