index.jsx 17.6 KB
Newer Older
A
afc163 已提交
1
import React from 'react';
A
afc163 已提交
2
import reqwest from 'reqwest';
A
afc163 已提交
3
import Table from 'rc-table';
A
afc163 已提交
4
import Checkbox from '../checkbox';
R
RaoHai 已提交
5
import Radio from '../radio';
A
afc163 已提交
6
import FilterDropdown from './filterDropdown';
7
import Pagination from '../pagination';
E
elrrrrrrr 已提交
8
import Icon from '../iconfont';
A
afc163 已提交
9
import objectAssign from 'object-assign';
A
afc163 已提交
10

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

Y
yiminghe 已提交
14 15 16
function defaultResolve(data) {
  return data || [];
}
17

18
class DataSource {
Y
yiminghe 已提交
19 20
  init(config) {
    this.config = config;
dqaria's avatar
dqaria 已提交
21
    this.url = config.url || '';
22 23 24
    this.resolve = config.resolve || defaultResolve;
    this.getParams = config.getParams || noop;
    this.getPagination = config.getPagination || noop;
A
afc163 已提交
25
    this.headers = config.headers || {};
A
afc163 已提交
26
    this.data = config.data || {};
Y
yiminghe 已提交
27 28 29 30 31 32 33 34
  }

  constructor(config) {
    if (config) {
      this.init(config);
    }
  }

35
  clone(config = {}) {
36
    return new DataSource(objectAssign({}, this.config, config));
37 38 39
  }
}

A
afc163 已提交
40
let AntTable = React.createClass({
Y
yiminghe 已提交
41
  getInitialState() {
A
afc163 已提交
42
    return {
Y
yiminghe 已提交
43
      // 减少状态
A
afc163 已提交
44
      selectedRowKeys: [],
Y
yiminghe 已提交
45 46
      // only for remote
      data: [],
47
      dataSource: this.props.dataSource,
Y
yiminghe 已提交
48
      filters: {},
R
RaoHai 已提交
49
      dirty: false,
50
      loading: false,
Y
yiminghe 已提交
51 52 53
      sortColumn: '',
      sortOrder: '',
      sorter: null,
R
RaoHai 已提交
54
      radioIndex: null,
Y
yiminghe 已提交
55
      pagination: this.hasPagination() ? objectAssign({
A
afc163 已提交
56 57
        pageSize: 10,
        current: 1
Y
yiminghe 已提交
58
      }, this.props.pagination) : {}
A
afc163 已提交
59 60
    };
  },
Y
yiminghe 已提交
61

A
afc163 已提交
62 63
  getDefaultProps() {
    return {
A
afc163 已提交
64
      prefixCls: 'ant-table',
A
afc163 已提交
65
      useFixedHeader: false,
A
afc163 已提交
66
      rowSelection: null,
A
afc163 已提交
67
      size: 'normal',
A
afc163 已提交
68 69
      bordered: false,
      onChange: function() {}
A
afc163 已提交
70 71
    };
  },
Y
yiminghe 已提交
72

A
afc163 已提交
73
  propTypes: {
A
afc163 已提交
74
    dataSource: React.PropTypes.oneOfType([React.PropTypes.array, React.PropTypes.instanceOf(DataSource)])
A
afc163 已提交
75 76
  },

R
RaoHai 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  getDefaultSelection() {
    let selectedRowKeys = [];
    if (this.props.rowSelection && this.props.rowSelection.getCheckboxProps) {
      let data = this.getCurrentPageData();
      data.filter((item) => {
        if (this.props.rowSelection.getCheckboxProps) {
          return this.props.rowSelection.getCheckboxProps(item).defaultValue;
        }
        return true;
      }).map((record, rowIndex) => {
        selectedRowKeys.push(this.getRecordKey(record, rowIndex));
      });
    }
    return selectedRowKeys;
  },

A
afc163 已提交
93
  componentWillReceiveProps(nextProps) {
Y
yiminghe 已提交
94
    if (('pagination' in nextProps) && nextProps.pagination !== false) {
95 96 97
      this.setState({
        pagination: objectAssign({}, this.state.pagination, nextProps.pagination)
      });
A
afc163 已提交
98
    }
99 100 101
    // 外界只有 dataSource 的变化会触发新请求
    if ('dataSource' in nextProps &&
        nextProps.dataSource !== this.props.dataSource) {
102
      this.setState({
103 104 105
        selectedRowKeys: [],
        dataSource: nextProps.dataSource,
        loading: true
106
      }, this.fetch);
Y
yiminghe 已提交
107 108
    }
    if (nextProps.columns !== this.props.columns) {
109 110 111
      this.setState({
        filters: {}
      });
A
afc163 已提交
112 113
    }
  },
A
afc163 已提交
114 115

  hasPagination(pagination) {
Y
yiminghe 已提交
116 117
    if (pagination === undefined) {
      pagination = this.props.pagination;
A
afc163 已提交
118
    }
Y
yiminghe 已提交
119 120
    return pagination !== false;
  },
A
afc163 已提交
121 122

  isLocalDataSource() {
123
    return Array.isArray(this.state.dataSource);
A
afc163 已提交
124
  },
A
afc163 已提交
125 126

  getRemoteDataSource() {
127
    return this.state.dataSource;
A
afc163 已提交
128
  },
A
afc163 已提交
129

A
afc163 已提交
130
  toggleSortOrder(order, column) {
131 132
    let sortColumn = this.state.sortColumn;
    let sortOrder = this.state.sortOrder;
J
jljsj 已提交
133
    let sorter;
A
afc163 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146
    // 只同时允许一列进行排序,否则会导致排序顺序的逻辑问题
    let isSortColumn = this.isSortColumn(column);
    if (!isSortColumn) {  // 当前列未排序
      sortOrder = order;
      sortColumn = column;
    } else {                      // 当前列已排序
      if (sortOrder === order) {  // 切换为未排序状态
        sortOrder = '';
        sortColumn = null;
      } else {                    // 切换为排序状态
        sortOrder = order;
      }
    }
Y
yiminghe 已提交
147 148
    if (this.isLocalDataSource()) {
      sorter = function () {
149
        let result = column.sorter.apply(this, arguments);
150
        if (sortOrder === 'ascend') {
151
          return result;
152
        } else if (sortOrder === 'descend') {
153 154 155
          return -result;
        }
      };
A
afc163 已提交
156
    }
A
afc163 已提交
157 158 159 160 161 162 163
    const newState = {
      sortOrder,
      sortColumn,
      sorter
    };
    this.fetch(newState);
    this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
A
afc163 已提交
164
  },
A
afc163 已提交
165

Y
yiminghe 已提交
166 167 168 169
  handleFilter(column, filters) {
    filters = objectAssign({}, this.state.filters, {
      [this.getColumnKey(column)]: filters
    });
A
afc163 已提交
170
    const newState = {
Y
yiminghe 已提交
171
      selectedRowKeys: [],
A
afc163 已提交
172 173 174 175
      filters
    };
    this.fetch(newState);
    this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
A
afc163 已提交
176
  },
A
afc163 已提交
177

Y
yiminghe 已提交
178
  handleSelect(record, rowIndex, e) {
A
afc163 已提交
179
    let checked = e.target.checked;
R
RaoHai 已提交
180 181 182 183 184
    let defaultSelection = [];
    if (!this.state.dirty) {
      defaultSelection = this.getDefaultSelection();
    }
    let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
Y
yiminghe 已提交
185
    let key = this.getRecordKey(record, rowIndex);
186
    if (checked) {
Y
yiminghe 已提交
187
      selectedRowKeys.push(this.getRecordKey(record, rowIndex));
188
    } else {
Y
yiminghe 已提交
189 190
      selectedRowKeys = selectedRowKeys.filter((i) => {
        return key !== i;
191 192 193
      });
    }
    this.setState({
R
RaoHai 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
      selectedRowKeys: selectedRowKeys,
      dirty: true
    });
    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 = [];
    if (!this.state.dirty) {
      defaultSelection = this.getDefaultSelection();
    }
    let selectedRowKeys = this.state.selectedRowKeys.concat(defaultSelection);
    let key = this.getRecordKey(record, rowIndex);
    selectedRowKeys = [key];
    this.setState({
      selectedRowKeys: selectedRowKeys,
      radioIndex: record.key,
      dirty: true
219 220
    });
    if (this.props.rowSelection.onSelect) {
Y
yiminghe 已提交
221 222 223
      let data = this.getCurrentPageData();
      let selectedRows = data.filter((row, i) => {
        return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
A
afc163 已提交
224
      });
Y
yiminghe 已提交
225
      this.props.rowSelection.onSelect(record, checked, selectedRows);
226 227
    }
  },
A
afc163 已提交
228

A
afc163 已提交
229 230
  handleSelectAllRow(e) {
    let checked = e.target.checked;
Y
yiminghe 已提交
231
    let data = this.getCurrentPageData();
R
RaoHai 已提交
232 233 234 235 236 237
    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 已提交
238 239
      return this.getRecordKey(item, i);
    }) : [];
A
afc163 已提交
240
    this.setState({
R
RaoHai 已提交
241 242
      selectedRowKeys: selectedRowKeys,
      dirty: true
243 244
    });
    if (this.props.rowSelection.onSelectAll) {
Y
yiminghe 已提交
245 246
      let selectedRows = data.filter((row, i) => {
        return selectedRowKeys.indexOf(this.getRecordKey(row, i)) >= 0;
A
afc163 已提交
247 248
      });
      this.props.rowSelection.onSelectAll(checked, selectedRows);
A
afc163 已提交
249
    }
A
afc163 已提交
250
  },
A
afc163 已提交
251

252
  handlePageChange(current) {
Y
yiminghe 已提交
253
    let pagination = objectAssign({}, this.state.pagination);
254 255 256 257 258
    if (current) {
      pagination.current = current;
    } else {
      pagination.current = pagination.current || 1;
    }
A
afc163 已提交
259
    const newState = {
Y
yiminghe 已提交
260 261
      // 防止内存泄漏,只维持当页
      selectedRowKeys: [],
A
afc163 已提交
262 263 264 265
      pagination
    };
    this.fetch(newState);
    this.props.onChange.apply(this, this.prepareParamsArguments(objectAssign({}, this.state, newState)));
266
  },
A
afc163 已提交
267

R
RaoHai 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
  onRadioChange: function (ev) {
    this.setState({
      radioIndex: ev.target.value
    });
  },

  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);
    }
    const checked = this.state.dirty ? this.state.radioIndex === record.key : this.getDefaultSelection().indexOf(rowIndex) >= 0;
    return <Radio disabled={props.disabled} onChange={this.handleRadioSelect.bind(this, record, rowIndex)} value={record.key} checked={checked} />;
  },

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

  getRecordKey(record, index) {
Y
yiminghe 已提交
295
    return record.key || index;
296
  },
A
afc163 已提交
297

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

A
afc163 已提交
344
  getCurrentPageData() {
Y
yiminghe 已提交
345 346 347
    return this.isLocalDataSource() ? this.getLocalDataPaging() : this.state.data;
  },

A
afc163 已提交
348 349 350 351 352 353 354 355 356 357 358
  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 已提交
359 360 361
  },

  renderColumnsDropdown(columns) {
Y
yiminghe 已提交
362
    return columns.map((column, i) => {
Y
yiminghe 已提交
363
      column = objectAssign({}, column);
A
afc163 已提交
364
      let key = this.getColumnKey(column, i);
A
afc163 已提交
365
      let filterDropdown, sortButton;
366
      if (column.filters && column.filters.length > 0) {
Y
yiminghe 已提交
367
        let colFilters = this.state.filters[key] || [];
A
afc163 已提交
368 369 370 371
        filterDropdown =
          <FilterDropdown column={column}
                          selectedKeys={colFilters}
                          confirmFilter={this.handleFilter} />;
A
afc163 已提交
372 373
      }
      if (column.sorter) {
A
afc163 已提交
374
        let isSortColumn = this.isSortColumn(column);
Y
yiminghe 已提交
375 376
        if (isSortColumn) {
          column.className = column.className || '';
A
afc163 已提交
377 378 379
          if (this.state.sortOrder) {
            column.className += ' ant-table-column-sort';
          }
Y
yiminghe 已提交
380
        }
A
afc163 已提交
381 382
        sortButton = <div className="ant-table-column-sorter">
          <span className={'ant-table-column-sorter-up ' +
383
                           ((isSortColumn && this.state.sortOrder === 'ascend') ? 'on' : 'off')}
Y
yiminghe 已提交
384 385
                title="升序排序"
                onClick={this.toggleSortOrder.bind(this, 'ascend', column)}>
E
elrrrrrrr 已提交
386
            <Icon type="caret-up" />
A
afc163 已提交
387 388
          </span>
          <span className={'ant-table-column-sorter-down ' +
389
                           ((isSortColumn && this.state.sortOrder === 'descend') ? 'on' : 'off')}
Y
yiminghe 已提交
390 391
                title="降序排序"
                onClick={this.toggleSortOrder.bind(this, 'descend', column)}>
E
elrrrrrrr 已提交
392
            <Icon type="caret-down" />
A
afc163 已提交
393 394 395
          </span>
        </div>;
      }
A
afc163 已提交
396 397 398 399 400
      column.title = <div>
        {column.title}
        {sortButton}
        {filterDropdown}
      </div>;
A
afc163 已提交
401
      return column;
A
afc163 已提交
402 403
    });
  },
A
afc163 已提交
404

405 406 407 408 409 410 411
  handleShowSizeChange(current, pageSize) {
    let pagination = objectAssign(this.state.pagination, {
      pageSize: pageSize
    });
    this.fetch({ pagination });
  },

412 413
  renderPagination() {
    // 强制不需要分页
Y
yiminghe 已提交
414 415
    if (!this.hasPagination()) {
      return null;
A
afc163 已提交
416
    }
A
afc163 已提交
417 418 419 420
    let classString = 'ant-table-pagination';
    if (this.props.size === 'small') {
      classString += ' mini';
    }
A
afc163 已提交
421 422
    let total = this.state.pagination.total;
    if (!total && this.isLocalDataSource()) {
Y
yiminghe 已提交
423 424
      total = this.getLocalData().length;
    }
A
afc163 已提交
425
    return (total > 0) ? <Pagination className={classString}
Y
yiminghe 已提交
426 427 428
                       onChange={this.handlePageChange}
                       total={total}
                       pageSize={10}
429
                       onShowSizeChange={this.handleShowSizeChange}
A
afc163 已提交
430
      {...this.state.pagination} /> : null;
A
afc163 已提交
431
  },
A
afc163 已提交
432

Y
yiminghe 已提交
433
  prepareParamsArguments(state) {
434 435 436
    // 准备筛选、排序、分页的参数
    let pagination;
    let filters = {};
A
afc163 已提交
437
    let sorter = {};
Y
yiminghe 已提交
438 439 440 441 442
    pagination = state.pagination;
    this.props.columns.forEach((column) => {
      let colFilters = state.filters[this.getColumnKey(column)] || [];
      if (colFilters.length > 0) {
        filters[this.getColumnKey(column)] = colFilters;
443 444
      }
    });
Y
yiminghe 已提交
445 446 447 448 449
    if (state.sortColumn &&
      state.sortOrder &&
      state.sortColumn.dataIndex) {
      sorter.field = state.sortColumn.dataIndex;
      sorter.order = state.sortOrder;
A
afc163 已提交
450 451
    }
    return [pagination, filters, sorter];
452
  },
Y
yiminghe 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465

  fetch(newState) {
    if (this.isLocalDataSource()) {
      if (newState) {
        this.setState(newState);
      }
    } else {
      let state = objectAssign({}, this.state, newState);
      if (newState || !this.state.loading) {
        this.setState(objectAssign({
          loading: true
        }, newState));
      }
A
afc163 已提交
466
      // remote 模式使用 this.dataSource
Y
yiminghe 已提交
467
      let dataSource = this.getRemoteDataSource();
A
afc163 已提交
468
      let buildInParams = dataSource.getParams.apply(this, this.prepareParamsArguments(state)) || {};
469
      return reqwest({
470
        url: dataSource.url,
471
        method: 'get',
A
afc163 已提交
472
        data: objectAssign(buildInParams, dataSource.data),
A
afc163 已提交
473
        headers: dataSource.headers,
474
        type: 'json',
A
afc163 已提交
475 476
        success: (result) => {
          if (this.isMounted()) {
A
afc163 已提交
477
            let pagination = objectAssign(
Y
yiminghe 已提交
478
              state.pagination,
A
afc163 已提交
479 480
              dataSource.getPagination.call(this, result)
            );
A
afc163 已提交
481
            this.setState({
R
RaoHai 已提交
482
              dirty: false,
Y
yiminghe 已提交
483
              loading: false,
484
              data: dataSource.resolve.call(this, result),
Y
yiminghe 已提交
485
              pagination: pagination
A
afc163 已提交
486 487 488
            });
          }
        },
A
afc163 已提交
489
        error: () => {
A
afc163 已提交
490
          this.setState({
Y
yiminghe 已提交
491 492
            loading: false,
            data: []
A
afc163 已提交
493 494 495
          });
        }
      });
Y
yiminghe 已提交
496 497 498
    }
  },

A
afc163 已提交
499
  findColumn(myKey) {
Y
yiminghe 已提交
500 501 502 503 504
    return this.props.columns.filter((c) => {
      return this.getColumnKey(c) === myKey;
    })[0];
  },

A
afc163 已提交
505
  getLocalDataPaging() {
Y
yiminghe 已提交
506 507 508 509 510 511 512
    let data = this.getLocalData();
    let current, pageSize;
    let state = this.state;
    // 如果没有分页的话,默认全部展示
    if (!this.hasPagination()) {
      pageSize = Number.MAX_VALUE;
      current = 1;
513
    } else {
Y
yiminghe 已提交
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
      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 已提交
532
  getLocalData() {
Y
yiminghe 已提交
533
    let state = this.state;
534
    let data = this.state.dataSource;
Y
yiminghe 已提交
535 536 537 538 539 540 541 542 543
    // 排序
    if (state.sortOrder && state.sorter) {
      data = data.sort(state.sorter);
    }
    // 筛选
    if (state.filters) {
      Object.keys(state.filters).forEach((columnKey) => {
        let col = this.findColumn(columnKey);
        let values = state.filters[columnKey] || [];
A
afc163 已提交
544 545 546
        if (values.length === 0) {
          return;
        }
Y
yiminghe 已提交
547 548 549 550
        data = data.filter((record) => {
          return values.some((v)=> {
            return col.onFilter(v, record);
          });
551
        });
A
afc163 已提交
552
      });
A
afc163 已提交
553
    }
Y
yiminghe 已提交
554
    return data;
A
afc163 已提交
555
  },
Y
yiminghe 已提交
556

A
afc163 已提交
557
  componentDidMount() {
Y
yiminghe 已提交
558 559 560
    if (!this.isLocalDataSource()) {
      this.fetch();
    }
A
afc163 已提交
561
  },
562

Y
yiminghe 已提交
563 564 565 566
  render() {
    let data = this.getCurrentPageData();
    let columns = this.renderRowSelection();
    let classString = '';
Z
zhujun24 已提交
567
    let expandIconAsCell = this.props.expandedRowRender && this.props.expandIconAsCell !== false;
A
afc163 已提交
568
    if (this.state.loading && !this.isLocalDataSource()) {
A
afc163 已提交
569 570 571 572 573
      classString += ' ant-table-loading';
    }
    if (this.props.size === 'small') {
      classString += ' ant-table-small';
    }
A
afc163 已提交
574 575 576
    if (this.props.bordered) {
      classString += ' ant-table-bordered';
    }
Y
yiminghe 已提交
577
    columns = this.renderColumnsDropdown(columns);
A
afc163 已提交
578 579 580 581
    columns = columns.map((column, i) => {
      column.key = column.dataIndex || i;
      return column;
    });
A
afc163 已提交
582
    let emptyText;
583
    let emptyClass = '';
A
afc163 已提交
584
    if (!data || data.length === 0) {
585
      emptyText = <div className="ant-table-placeholder">
E
elrrrrrrr 已提交
586
        <Icon type="frown" />暂无数据
A
afc163 已提交
587
      </div>;
588
      emptyClass = ' ant-table-empty';
A
afc163 已提交
589
    }
590
    return <div className={'clearfix' + emptyClass}>
Y
yiminghe 已提交
591 592
      <Table
        {...this.props}
A
afc163 已提交
593
        data={data}
Y
yiminghe 已提交
594 595
        columns={columns}
        className={classString}
Z
zhujun24 已提交
596
        expandIconAsCell={expandIconAsCell}
Y
yiminghe 已提交
597
        />
A
afc163 已提交
598
      {emptyText}
599 600
      {this.renderPagination()}
    </div>;
A
afc163 已提交
601 602
  }
});
603 604 605

AntTable.DataSource = DataSource;

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