React+antd获取表格数据并展示
2019-05-30 14:30
951 查看
import React, { Component, PropTypes } from ‘react’;
import { Input, Col, Row, Button, Table, message, Pagination} from ‘antd’;
import ‘./style.scss’;
import api from ‘…/…/…/…/common/urlconfig’;
import fetch from ‘…/…/…/…/util/fetch’
const InputGroup = Input.Group;
const columns = [
{
title: ‘序号’,
dataIndex: ‘index’,
},
{
title: ‘用户名’,
dataIndex: ‘userName’,
},
{
title: ‘姓名’,
dataIndex: ‘fullName’,
},
{
title: ‘部门’,
dataIndex: ‘orgName’,
},
{
title: ‘用户当前状态’,
dataIndex: ‘accountState’,
},
{
title: ‘学时数’,
dataIndex: ‘studyHour’,
},
];
class Learns extends Component{
static propTypes = {
}; static defaultProps = { }; constructor(props){ super(props); this.state = { pageNo : 1, pageSize : 10, isLoaded : false, nameValue : "", codeValue : "", total : 0, current : 1, pageObj : {}, data : [], }; } componentWillMount() { } componentDidMount() { const { nameValue = undefined, codeValue = undefined,pageNo,pageSize} = this.state; console.log(codeValue); this.InputGroup({pageNo,pageSize,nameValue,codeValue}); } InputGroup = (parm) => { const detail={ pageNo : parm.pageNo, pageSize : parm.pageSize, userName : parm.nameValue, orgNameLike : parm.codeValue, }; fetch(api.echartUrl+'后台接口',{type:'GET',data:detail}) .then((res) => { this.setState({ data :res.data.records, pageObj :res.page, current :res.page.pageNo, }) }) }; //用户名点击回调 nameChange = (value) => { this.setState({ nameValue:value }); }; codeChange = (value) => { this.setState({ codeValue:value }); }; //搜索组件 timeSearch = () => { const { nameValue = undefined, codeValue = undefined,pageNo,pageSize} = this.state; console.log(codeValue); this.InputGroup({pageNo,pageSize,nameValue,codeValue}); }; //下载组件 downTxt = () => { const {nameValue,codeValue}=this.state; const data = { orgNameLike : codeValue, userName : nameValue }; fetch(api.echartUrl+'后台下载接口',{type:'GET',data:data}) .then((res) => { console.log(res); if (res.code === '1000'){ message.success(res.data); } else { message.error(res.subMsg) } }) }; // 分页子组件 showTotal = (total) =>{ return `共计 ${total} 条`; }; // 分页组件 pageChange = (pageNo,pageSize)=>{ const { nameValue = undefined, codeValue = undefined} = this.state; console.log(codeValue); this.InputGroup({pageNo,pageSize,nameValue,codeValue}); }; render() { const { data,pageObj } = this.state; return( <div> <h1>学时统计</h1> <InputGroup size="middle"> <Row gutter={8}> <Col span={5}> <Input className="nameValue" placeholder="请输入部门关键词" onChange={(e) => {this.nameChange(e.target.value)}}/> </Col> <Col span={5}> <Input className="codeValue" placeholder="请输入用户关键词" onChange={(e) => {this.codeChange(e.target.value)}}/> </Col> <Button type="primary" icon="search" onClick={this.timeSearch}>查询</Button> <Button type="primary" icon="download" onClick={this.downTxt}>下载数据统计</Button> </Row> </InputGroup> <Table columns={columns} dataSource={data} pagination={false} rowKey="index" /> <Pagination style={{textAlign:"right", marginTop:"10px", marginRight:"40px"}} showQuickJumper defaultCurrent={1} current={this.state.current} total={pageObj.pageTotal} showTotal={this.showTotal} onChange={this.pageChange} /> </div>) }
}
export default Learns
相关文章推荐
- Antd(Ant-design),嵌套子表格(expandedRowRender)的异步获取数据
- 用JS获取表格单元中的数据
- 分享一个表格数据展示插件
- EasyUI DataGrid DetailView(数据表格详细展示带子表格)
- 表格和图在数据展示上面的思考
- JS如何实现获取表格中的单元格里面的数据,并让其累加
- 获取网络数据进行Gson解析用ListView展示
- iOS--JSON解析后如何获取数据,并且展示到相应cell上
- 获取带复选框的easyui表格选中的行数据
- boostrap-table插件分页展示表格数据
- 小白学react之restful api获取服务器数据实战
- 前台JSP页面以表格展示数据的过程中出现了重复数据
- 开发一个基于React Native的简易demo--读取网络数据并展示
- ajax实现点击按钮从后台获取数据 以表格显示内容
- JQuery获取表格数据示例代码
- 获取后台数据展示在下拉框列表
- Relay: 全新的React数据获取框架
- jquery遍历表格获取表格当前行数据
- 跨平台获取外部系统的数据解析成json并传输到前台展示成列表
- jquery获取表格数据