import React, { PureComponent } from "react";
import { Table } from "antd";
import styles from "./index.less";

class PageGrid extends PureComponent {
  onShowSizeChange(current, pageSize) {
    this.props.search(current - 1, pageSize);
  }
  onRowClickHandle(record) {
    const { onRow } = this.props;
    if (onRow) {
      onRow(record);
    }
  }
  paginationChange(page, pageSize) {
    this.props.search(page - 1, pageSize);
  }
  render() {
    const { columns } = this.props;
    const pageGridSource = this.props.pageGridSource || {};
    pageGridSource.content = Array.isArray(pageGridSource.content) ? pageGridSource.content : [];
    const paginationSetting = {
        size: "small",
        pageSize: pageGridSource.size ? pageGridSource.size : 10,
        total: pageGridSource.totalElements ? pageGridSource.totalElements : 0,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: this.showTotalFun,
        onShowSizeChange: this.onShowSizeChange.bind(this),
        onChange: this.paginationChange.bind(this)
    };
    return (
      <div className={styles.pageGridBox}>
        <Table
          columns={columns}
          rowSelection={this.props.rowSelection}
          dataSource={pageGridSource.content}
          pagination={paginationSetting}
          onRowClick={this.onRowClickHandle.bind(this)}
        />
      </div>
    );
  }
}
export default PageGrid;
