index.jsx 17.4 KB
Newer Older
A
afc163 已提交
1 2
import React from 'react';
import Table from 'rc-table';
A
afc163 已提交
3
import Checkbox from '../checkbox';
R
RaoHai 已提交
4
import Radio from '../radio';
A
afc163 已提交
5
import FilterDropdown from './filterDropdown';
6
import Pagination from '../pagination';
A
afc163 已提交
7
import Icon from '../icon';
A
afc163 已提交
8
import objectAssign from 'object-assign';
K
KgTong 已提交
9
import Spin from '../spin';
A
afc163 已提交
10
import classNames from 'classnames';
A
afc163 已提交
11

Y
yiminghe 已提交
12 13
function noop() {
}
14

B
Benjy Cui 已提交
15 16 17
const defaultLocale = {
  filterTitle: '筛选',
  filterConfirm: '确定',
A
afc163 已提交
18 19
  filterReset: '重置',
  emptyText: '暂无数据',
B
Benjy Cui 已提交
20 21
};

A
afc163 已提交
22
let AntTable = React.createClass({
Y
yiminghe 已提交
23
  getInitialState() {
A
afc163 已提交
24
    return {
Y
yiminghe 已提交
25
      // 减少状态
A
afc163 已提交
26
      selectedRowKeys: [],
Y
yiminghe 已提交
27
      filters: {},
A
afc163 已提交
28
      selectionDirty: false,
Y
yiminghe 已提交
29 30 31
      sortColumn: '',
      sortOrder: '',
      sorter: null,
R
RaoHai 已提交
32
      radioIndex: null,
Y
yiminghe 已提交
33
      pagination: this.hasPagination() ? objectAssign({
A
afc163 已提交
34 35
        pageSize: 10,
        current: 1
Y
yiminghe 已提交
36
      }, this.props.pagination) : {}
A
afc163 已提交
37 38
    };
  },
Y
yiminghe 已提交
39

A
afc163 已提交
40 41
  getDefaultProps() {
    return {
A
afc163 已提交
42
      dataSource: [],
A
afc163 已提交
43
      prefixCls: 'ant-table',
A
afc163 已提交
44
      useFixedHeader: false,
A
afc163 已提交
45
      rowSelection: null,
Y
yiminghe 已提交
46
      className: '',
A
afc163 已提交
47
      size: 'large',
A
afc163 已提交
48
      loading: false,
A
afc163 已提交
49
      bordered: false,
B
Benjy Cui 已提交
50 51
      onChange: noop,
      locale: {}
A
afc163 已提交
52 53
    };
  },
Y
yiminghe 已提交
54

A
afc163 已提交
55
  propTypes: {
A
afc163 已提交
56
    dataSource: React.PropTypes.array,
A
afc163 已提交
57 58 59 60 61 62 63 64 65
    prefixCls: React.PropTypes.string,
    useFixedHeader: React.PropTypes.bool,
    rowSelection: React.PropTypes.object,
    className: React.PropTypes.string,
    size: React.PropTypes.string,
    loading: React.PropTypes.bool,
    bordered: React.PropTypes.bool,
    onChange: React.PropTypes.func,
    locale: React.PropTypes.object,
A
afc163 已提交
66 67
  },

R
RaoHai 已提交
68 69 70 71 72 73
  getDefaultSelection() {
    let selectedRowKeys = [];
    if (this.props.rowSelection && this.props.rowSelection.getCheckboxProps) {
      let data = this.getCurrentPageData();
      data.filter((item) => {
        if (this.props.rowSelection.getCheckboxProps) {
74
          return this.props.rowSelection.getCheckboxProps(item).defaultChecked;
R
RaoHai 已提交
75 76 77 78 79 80 81 82 83
        }
        return true;
      }).map((record, rowIndex) => {
        selectedRowKeys.push(this.getRecordKey(record, rowIndex));
      });
    }
    return selectedRowKeys;
  },

A
afc163 已提交
84
  componentWillReceiveProps(nextProps) {
Y
yiminghe 已提交
85
    if (('pagination' in nextProps) && nextProps.pagination !== false) {
86 87 88
      this.setState({
        pagination: objectAssign({}, this.state.pagination, nextProps.pagination)
      });
A
afc163 已提交
89
    }
90 91
    // 外界只有 dataSource 的变化会触发新请求
    if ('dataSource' in nextProps &&
A
afc163 已提交
92 93 94
        nextProps.dataSource !== this.props.dataSource) {
      let selectedRowKeys = this.state.selectedRowKeys;
      // 把不在当前页的选中项去掉
A
afc163 已提交
95 96 97 98 99 100 101
      let currentPageRowKeys =
        this.getCurrentPageData(nextProps.dataSource).map(
          (record, i) => this.getRecordKey(record, i)
        );
      selectedRowKeys = selectedRowKeys.filter((key) => {
        return currentPageRowKeys.indexOf(key) >= 0;
      });
102
      this.setState({
A
afc163 已提交
103
        selectionDirty: false,
A
afc163 已提交
104
        selectedRowKeys,
A
afc163 已提交
105 106
      });
    }
A
afc163 已提交
107
  },
A
afc163 已提交
108

A
afc163 已提交
109
  hasPagination() {
A
afc163 已提交
110
    return this.props.pagination !== false;
A
afc163 已提交
111
  },
A
afc163 已提交
112

A
afc163 已提交
113
  toggleSortOrder(order, column) {
114 115
    let sortColumn = this.state.sortColumn;
    let sortOrder = this.state.sortOrder;
J
jljsj 已提交
116
    let sorter;
A
afc163 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129
    // 只同时允许一列进行排序,否则会导致排序顺序的逻辑问题
    let isSortColumn = this.isSortColumn(column);
    if (!isSortColumn) {  // 当前列未排序
      sortOrder = order;
      sortColumn = column;
    } else {                      // 当前列已排序
      if (sortOrder === order) {  // 切换为未排序状态
        sortOrder = '';
        sortColumn = null;
      } else {                    // 切换为排序状态
        sortOrder = order;
      }
    }
A
afc163 已提交
130
    if (typeof column.sorter === 'function') {
Y
yiminghe 已提交
131
      sorter = function () {
132
        let result = column.sorter.apply(this, arguments);
133
        if (sortOrder === 'ascend') {
134
          return result;
135
        } else if (sortOrder === 'descend') {
136 137 138
          return -result;
        }
      };
A
afc163 已提交
139
    }
A
afc163 已提交
140 141 142 143 144
    const newState = {
      sortOrder,
      sortColumn,
      sorter
    };
A
afc163 已提交
145
    this.setState(newState);
A
afc163 已提交
146
    this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
A
afc163 已提交
147
  },
A
afc163 已提交
148

Y
yiminghe 已提交
149 150 151 152
  handleFilter(column, filters) {
    filters = objectAssign({}, this.state.filters, {
      [this.getColumnKey(column)]: filters
    });
153 154 155 156 157 158 159
    // Remove filters not in current columns
    const currentColumnKeys = this.props.columns.map(c => this.getColumnKey(c));
    Object.keys(filters).forEach((columnKey) => {
      if (currentColumnKeys.indexOf(columnKey) < 0) {
        delete filters[columnKey];
      }
    });
A
afc163 已提交
160
    const newState = {
Y
yiminghe 已提交
161
      selectedRowKeys: [],
A
afc163 已提交
162
      selectionDirty: false,
A
afc163 已提交
163 164
      filters
    };
A
afc163 已提交
165
    this.setState(newState);
A
afc163 已提交
166
    this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
A
afc163 已提交
167
  },
A
afc163 已提交
168

Y
yiminghe 已提交
169
  handleSelect(record, rowIndex, e) {
A
afc163 已提交
170
    let checked = e.target.checked;
R
RaoHai 已提交
171
    let defaultSelection = [];
A
afc163 已提交
172
    if (!this.state.selectionDirty) {
R
RaoHai 已提交
173 174 175
      defaultSelection = this.getDefaultSelection();
    }
    let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
Y
yiminghe 已提交
176
    let key = this.getRecordKey(record, rowIndex);
177
    if (checked) {
Y
yiminghe 已提交
178
      selectedRowKeys.push(this.getRecordKey(record, rowIndex));
179
    } else {
Y
yiminghe 已提交
180 181
      selectedRowKeys = selectedRowKeys.filter((i) => {
        return key !== i;
182 183 184
      });
    }
    this.setState({
R
RaoHai 已提交
185
      selectedRowKeys: selectedRowKeys,
A
afc163 已提交
186
      selectionDirty: true
R
RaoHai 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199
    });
    if (this.props.rowSelection.onSelect) {
      let data = this.getCurrentPageData();
      let selectedRows = data.filter((row, i) => {
        return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
      });
      this.props.rowSelection.onSelect(record, checked, selectedRows);
    }
  },

  handleRadioSelect: function (record, rowIndex, e) {
    let checked = e.target.checked;
    let defaultSelection = [];
A
afc163 已提交
200
    if (!this.state.selectionDirty) {
R
RaoHai 已提交
201 202 203 204 205 206 207
      defaultSelection = this.getDefaultSelection();
    }
    let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
    let key = this.getRecordKey(record, rowIndex);
    selectedRowKeys = [key];
    this.setState({
      selectedRowKeys: selectedRowKeys,
208
      radioIndex: key,
A
afc163 已提交
209
      selectionDirty: true
210 211
    });
    if (this.props.rowSelection.onSelect) {
Y
yiminghe 已提交
212 213 214
      let data = this.getCurrentPageData();
      let selectedRows = data.filter((row, i) => {
        return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
A
afc163 已提交
215
      });
Y
yiminghe 已提交
216
      this.props.rowSelection.onSelect(record, checked, selectedRows);
217 218
    }
  },
A
afc163 已提交
219

A
afc163 已提交
220 221
  handleSelectAllRow(e) {
    let checked = e.target.checked;
Y
yiminghe 已提交
222
    let data = this.getCurrentPageData();
R
RaoHai 已提交
223 224 225 226 227 228
    let selectedRowKeys = checked ? data.filter((item) => {
      if (this.props.rowSelection.getCheckboxProps) {
        return !this.props.rowSelection.getCheckboxProps(item).disabled;
      }
      return true;
    }).map((item, i) => {
Y
yiminghe 已提交
229 230
      return this.getRecordKey(item, i);
    }) : [];
A
afc163 已提交
231
    this.setState({
R
RaoHai 已提交
232
      selectedRowKeys: selectedRowKeys,
A
afc163 已提交
233
      selectionDirty: true
234 235
    });
    if (this.props.rowSelection.onSelectAll) {
Y
yiminghe 已提交
236 237
      let selectedRows = data.filter((row, i) => {
        return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
A
afc163 已提交
238 239
      });
      this.props.rowSelection.onSelectAll(checked, selectedRows);
A
afc163 已提交
240
    }
A
afc163 已提交
241
  },
A
afc163 已提交
242

243
  handlePageChange(current) {
Y
yiminghe 已提交
244
    let pagination = objectAssign({}, this.state.pagination);
245 246 247 248 249
    if (current) {
      pagination.current = current;
    } else {
      pagination.current = pagination.current || 1;
    }
A
afc163 已提交
250
    const newState = {
Y
yiminghe 已提交
251 252
      // 防止内存泄漏,只维持当页
      selectedRowKeys: [],
A
afc163 已提交
253
      selectionDirty: false,
A
afc163 已提交
254 255
      pagination
    };
A
afc163 已提交
256
    this.setState(newState);
A
afc163 已提交
257
    this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
258
  },
A
afc163 已提交
259

R
RaoHai 已提交
260 261 262
  onRadioChange: function (ev) {
    this.setState({
      radioIndex: ev.target.value
Y
yiminghe 已提交
263
    });
264
  },
A
afc163 已提交
265

R
RaoHai 已提交
266 267 268 269 270 271
  renderSelectionRadio(value, record, index) {
    let rowIndex = this.getRecordKey(record, index); // 从 1 开始
    let props = {};
    if (this.props.rowSelection.getCheckboxProps) {
      props = this.props.rowSelection.getCheckboxProps.call(this, record);
    }
A
afc163 已提交
272 273
    let checked;
    if (this.state.selectionDirty) {
274
      checked = this.state.radioIndex === rowIndex;
A
afc163 已提交
275
    } else {
276
      checked = (this.state.radioIndex === rowIndex ||
A
afc163 已提交
277 278
                 this.getDefaultSelection().indexOf(rowIndex) >= 0);
    }
Y
yiminghe 已提交
279
    return <Radio disabled={props.disabled} onChange={this.handleRadioSelect.bind(this, record, rowIndex)}
280
                  value={rowIndex} checked={checked}/>;
R
RaoHai 已提交
281 282
  },

283
  renderSelectionCheckBox(value, record, index) {
Y
yiminghe 已提交
284
    let rowIndex = this.getRecordKey(record, index); // 从 1 开始
A
afc163 已提交
285 286 287 288 289 290 291
    let checked;
    if (this.state.selectionDirty) {
      checked = this.state.selectedRowKeys.indexOf(rowIndex) >= 0;
    } else {
      checked = (this.state.selectedRowKeys.indexOf(rowIndex) >= 0 ||
                 this.getDefaultSelection().indexOf(rowIndex) >= 0);
    }
R
RaoHai 已提交
292 293 294 295
    let props = {};
    if (this.props.rowSelection.getCheckboxProps) {
      props = this.props.rowSelection.getCheckboxProps.call(this, record);
    }
Y
yiminghe 已提交
296 297
    return <Checkbox checked={checked} disabled={props.disabled}
                     onChange={this.handleSelect.bind(this, record, rowIndex)}/>;
Y
yiminghe 已提交
298
  },
A
afc163 已提交
299 300

  getRecordKey(record, index) {
301 302 303
    if (this.props.rowKey) {
      return this.props.rowKey(record, index);
    }
Y
yiminghe 已提交
304
    return record.key || index;
305
  },
A
afc163 已提交
306

307
  renderRowSelection() {
Y
yiminghe 已提交
308
    let columns = this.props.columns.concat();
309
    if (this.props.rowSelection) {
310 311 312 313 314 315
      let data = this.getCurrentPageData().filter((item) => {
        if (this.props.rowSelection.getCheckboxProps) {
          return !this.props.rowSelection.getCheckboxProps(item).disabled;
        }
        return true;
      });
Y
yiminghe 已提交
316 317 318 319
      let checked;
      if (!data.length) {
        checked = false;
      } else {
A
afc163 已提交
320 321 322
        checked = this.state.selectionDirty
          ? data.every((item, i) =>
              this.state.selectedRowKeys.indexOf(this.getRecordKey(item, i)) >= 0)
A
afc163 已提交
323
          : data.every((item) =>
A
afc163 已提交
324 325
              this.props.rowSelection.getCheckboxProps &&
              this.props.rowSelection.getCheckboxProps(item).defaultChecked);
Y
yiminghe 已提交
326
      }
R
RaoHai 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
      let selectionColumn;
      if (this.props.rowSelection.type === 'radio') {
        selectionColumn = {
          key: 'selection-column',
          render: this.renderSelectionRadio,
          className: 'ant-table-selection-column'
        };
      } else {
        let checkboxAll = <Checkbox checked={checked} onChange={this.handleSelectAllRow}/>;
        selectionColumn = {
          key: 'selection-column',
          title: checkboxAll,
          render: this.renderSelectionCheckBox,
          className: 'ant-table-selection-column'
        };
      }
343
      if (columns[0] &&
Y
yiminghe 已提交
344
        columns[0].key === 'selection-column') {
345 346 347 348 349 350 351
        columns[0] = selectionColumn;
      } else {
        columns.unshift(selectionColumn);
      }
    }
    return columns;
  },
Y
yiminghe 已提交
352

A
afc163 已提交
353 354 355 356 357 358 359 360 361 362 363
  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;
Y
yiminghe 已提交
364 365 366
  },

  renderColumnsDropdown(columns) {
B
Benjy Cui 已提交
367
    let locale = objectAssign({}, defaultLocale, this.props.locale);
Y
yiminghe 已提交
368
    return columns.map((column, i) => {
Y
yiminghe 已提交
369
      column = objectAssign({}, column);
A
afc163 已提交
370
      let key = this.getColumnKey(column, i);
A
afc163 已提交
371
      let filterDropdown, sortButton;
372
      if (column.filters && column.filters.length > 0) {
Y
yiminghe 已提交
373
        let colFilters = this.state.filters[key] || [];
A
afc163 已提交
374
        filterDropdown =
B
Benjy Cui 已提交
375
          <FilterDropdown locale={locale} column={column}
A
afc163 已提交
376
                          selectedKeys={colFilters}
Y
yiminghe 已提交
377
                          confirmFilter={this.handleFilter}/>;
A
afc163 已提交
378 379
      }
      if (column.sorter) {
A
afc163 已提交
380
        let isSortColumn = this.isSortColumn(column);
Y
yiminghe 已提交
381 382
        if (isSortColumn) {
          column.className = column.className || '';
A
afc163 已提交
383 384 385
          if (this.state.sortOrder) {
            column.className += ' ant-table-column-sort';
          }
Y
yiminghe 已提交
386
        }
B
Benjy Cui 已提交
387

A
afc163 已提交
388 389
        sortButton = <div className="ant-table-column-sorter">
          <span className={'ant-table-column-sorter-up ' +
390
                           ((isSortColumn && this.state.sortOrder === 'ascend') ? 'on' : 'off')}
A
afc163 已提交
391
                title="↑"
Y
yiminghe 已提交
392
                onClick={this.toggleSortOrder.bind(this, 'ascend', column)}>
Y
yiminghe 已提交
393
            <Icon type="caret-up"/>
A
afc163 已提交
394 395
          </span>
          <span className={'ant-table-column-sorter-down ' +
396
                           ((isSortColumn && this.state.sortOrder === 'descend') ? 'on' : 'off')}
A
afc163 已提交
397
                title="↓"
Y
yiminghe 已提交
398
                onClick={this.toggleSortOrder.bind(this, 'descend', column)}>
Y
yiminghe 已提交
399
            <Icon type="caret-down"/>
A
afc163 已提交
400 401 402
          </span>
        </div>;
      }
A
afc163 已提交
403 404 405 406 407
      column.title = <div>
        {column.title}
        {sortButton}
        {filterDropdown}
      </div>;
A
afc163 已提交
408
      return column;
A
afc163 已提交
409 410
    });
  },
A
afc163 已提交
411

412
  handleShowSizeChange(current, pageSize) {
B
Benjy Cui 已提交
413 414 415 416 417 418
    const pagination = this.state.pagination;
    if (pagination.onShowSizeChange) {
      pagination.onShowSizeChange(current, pageSize);
    }

    let nextPagination = objectAssign(pagination, {
419 420
      pageSize: pageSize
    });
B
Benjy Cui 已提交
421
    this.setState({ pagination: nextPagination });
422 423
  },

424 425
  renderPagination() {
    // 强制不需要分页
Y
yiminghe 已提交
426 427
    if (!this.hasPagination()) {
      return null;
A
afc163 已提交
428
    }
A
afc163 已提交
429 430 431 432
    let classString = classNames({
      'ant-table-pagination': true,
      'mini': this.props.size === 'middle' || this.props.size === 'small',
    });
A
afc163 已提交
433
    let total = this.state.pagination.total || this.getLocalData().length;
Y
yiminghe 已提交
434
    const pageSize = this.state.pagination.pageSize;
A
afc163 已提交
435
    return (total > 0) ?
B
Benjy Cui 已提交
436 437
      <Pagination {...this.state.pagination}
                  className={classString}
A
afc163 已提交
438 439
                  onChange={this.handlePageChange}
                  total={total}
Y
yiminghe 已提交
440
                  pageSize={pageSize}
B
Benjy Cui 已提交
441
                  onShowSizeChange={this.handleShowSizeChange} /> : null;
A
afc163 已提交
442
  },
A
afc163 已提交
443

Y
yiminghe 已提交
444
  prepareParamsArguments(state) {
445
    // 准备筛选、排序、分页的参数
446 447 448
    const pagination = state.pagination;
    const filters = state.filters;
    const sorter = {};
Y
yiminghe 已提交
449 450 451 452 453
    if (state.sortColumn &&
      state.sortOrder &&
      state.sortColumn.dataIndex) {
      sorter.field = state.sortColumn.dataIndex;
      sorter.order = state.sortOrder;
A
afc163 已提交
454 455
    }
    return [pagination, filters, sorter];
456
  },
Y
yiminghe 已提交
457

A
afc163 已提交
458
  findColumn(myKey) {
Y
yiminghe 已提交
459 460 461 462 463
    return this.props.columns.filter((c) => {
      return this.getColumnKey(c) === myKey;
    })[0];
  },

A
afc163 已提交
464
  getCurrentPageData(dataSource) {
A
afc163 已提交
465
    let data = this.getLocalData(dataSource);
Y
yiminghe 已提交
466 467 468 469 470 471
    let current, pageSize;
    let state = this.state;
    // 如果没有分页的话,默认全部展示
    if (!this.hasPagination()) {
      pageSize = Number.MAX_VALUE;
      current = 1;
472
    } else {
Y
yiminghe 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
      pageSize = state.pagination.pageSize;
      current = state.pagination.current;
    }
    // 分页
    // ---
    // 当数据量少于每页数量时,直接设置数据
    // 否则进行读取分页数据
    if (data.length > pageSize || pageSize === Number.MAX_VALUE) {
      data = data.filter((item, i) => {
        if (i >= (current - 1) * pageSize &&
          i < current * pageSize) {
          return item;
        }
      });
    }
    return data;
  },

A
afc163 已提交
491
  getLocalData(dataSource) {
Y
yiminghe 已提交
492
    let state = this.state;
A
afc163 已提交
493
    let data = dataSource || this.props.dataSource;
Y
yiminghe 已提交
494 495 496 497 498 499 500 501
    // 排序
    if (state.sortOrder && state.sorter) {
      data = data.sort(state.sorter);
    }
    // 筛选
    if (state.filters) {
      Object.keys(state.filters).forEach((columnKey) => {
        let col = this.findColumn(columnKey);
502 503 504
        if (!col) {
          return;
        }
Y
yiminghe 已提交
505
        let values = state.filters[columnKey] || [];
A
afc163 已提交
506 507 508
        if (values.length === 0) {
          return;
        }
A
afc163 已提交
509 510 511
        data = col.onFilter ? data.filter(record => {
          return values.some(v => col.onFilter(v, record));
        }) : data;
A
afc163 已提交
512
      });
A
afc163 已提交
513
    }
Y
yiminghe 已提交
514
    return data;
A
afc163 已提交
515
  },
Y
yiminghe 已提交
516 517 518 519

  render() {
    let data = this.getCurrentPageData();
    let columns = this.renderRowSelection();
Z
zhujun24 已提交
520
    let expandIconAsCell = this.props.expandedRowRender && this.props.expandIconAsCell !== false;
A
afc163 已提交
521
    let locale = objectAssign({}, defaultLocale, this.props.locale);
A
afc163 已提交
522 523 524 525 526 527 528

    let classString = classNames({
      [`ant-table-${this.props.size}`]: true,
      'ant-table-bordered': this.props.bordered,
      [this.props.className]: !!this.props.className,
    });

Y
yiminghe 已提交
529
    columns = this.renderColumnsDropdown(columns);
A
afc163 已提交
530
    columns = columns.map((column, i) => {
A
afc163 已提交
531
      column.key = column.key || column.dataIndex || i;
A
afc163 已提交
532 533
      return column;
    });
A
afc163 已提交
534
    let emptyText;
535
    let emptyClass = '';
A
afc163 已提交
536
    if (!data || data.length === 0) {
537
      emptyText = <div className="ant-table-placeholder">
A
afc163 已提交
538
        <Icon type="frown"/>{locale.emptyText}
A
afc163 已提交
539
      </div>;
540
      emptyClass = ' ant-table-empty';
A
afc163 已提交
541
    }
A
afc163 已提交
542

A
afc163 已提交
543
    let table = <div>
544 545 546 547 548
      <Table {...this.props}
        data={data}
        columns={columns}
        className={classString}
        expandIconAsCell={expandIconAsCell} />
A
afc163 已提交
549 550
      {emptyText}
    </div>;
A
afc163 已提交
551
    if (this.props.loading) {
K
KgTong 已提交
552 553 554 555
      // if there is no pagination or no data, the height of spin should decrease by half of pagination
      let paginationPatchClass = (this.hasPagination() && data && data.length !== 0)
              ? 'ant-table-with-pagination'
              : 'ant-table-without-pagination';
A
afc163 已提交
556
      let spinClassName = `${paginationPatchClass} ant-table-spin-holder`;
557
      table = <Spin className={spinClassName}>{table}</Spin>;
A
afc163 已提交
558
    }
559 560 561 562 563 564
    return (
      <div className={'clearfix' + emptyClass}>
        {table}
        {this.renderPagination()}
      </div>
    );
A
afc163 已提交
565 566
  }
});
567

dqaria's avatar
dqaria 已提交
568
export default AntTable;