New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

antd-datagrid

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antd-datagrid

datagrid use antd

latest
Source
npmnpm
Version
0.3.5
Version published
Weekly downloads
11
-15.38%
Maintainers
1
Weekly downloads
 
Created
Source

发布

> npm run babel

demo

依赖以及配置

安装babelwebpack等配套开发设施,配置如下:

babel配置:

{
    "presets": ["es2015", "react"],
    "plugins":[["import", { "libraryName": "antd", "style": "css" }]]
}

webpack配置:

//webpack.config.js

const path=require('path');

const PATH={
    dist:path.join(__dirname,"dist"),
};

module.exports={
    entry:{
        index:path.join(__dirname,'index.js'),
    },
    output:{
        path:PATH.dist,
        filename:'[name].js',
    },
    module:{
        loaders:[
            {
                test:/\.jsx?/,
                loaders:['babel-loader'],
                exclude:'node_modules',
            },
            {
                test:/\.css$/,
                loaders:['style-loader','css-loader'],
            },
        ],
    },
};

除本项目的依赖之外,还要再安装reactreact-domantd等依赖。

使用

使用antd-datagrid编写一个List 组件:

// lib/list.js 
import React from 'react';
import Datagrid from 'antd-datagrid';

export const List=React.createClass({

    render:function(){
        return (<div>
            <Datagrid 
                columns={[
                    {title:'title',dataIndex:'title'}, 
                    {title:'status',dataIndex:'status'},
                    {title:'createdAt',dataIndex:'createdAt'},
                    {title:'updatedAt',dataIndex:'updatedAt'},
                ]}
                fetch={(page,size,condition)=>{
                    return new Promise(function(resolve,reject){
                        const data={
                            rows:[
                                {title:`${page}-1`,status:`${(page-1)*size}`,createdAt:(new Date()).toString(),updatedAt:(new Date()).toString()},
                                {title:`${page}-2`,status:`${(page-1)*size+1}`,createdAt:(new Date()).toString(),updatedAt:(new Date()).toString()},
                                {title:`${page}-3`,status:`${(page-1)*size+2}`,createdAt:(new Date()).toString(),updatedAt:(new Date()).toString()},
                                {title:`${page}-4`,status:`${(page-1)*size+3}`,createdAt:(new Date()).toString(),updatedAt:(new Date()).toString()},
                                {title:`${page}-5`,status:`${(page-1)*size+4}`,createdAt:(new Date()).toString(),updatedAt:(new Date()).toString()},
                            ],
                            count:100,
                        };
                        resolve(data);
                    });
                }} 
                onRowClick={(record,index)=>{
                    console.log(record,index);
                }}
                refreshCode={1}
            />
        </div>);
    }
})


export default List;

我们打算让他在HTML中显示出来,先编写一个HTML模板:

<html>
<head></head>
<body>
    <div id="app"></div>
    <script src="./index.js"></script>
</body>
</html>

主要把上面的index.js更换为实际发布js地址的路径。

编写入口文件:

// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import List from  './lib/list';


ReactDOM.render(<List/>,document.getElementById('app'));

打包

使用webpack打包,执行:

> npm run webpack 

运行

执行HTML模板文件,即可显示Datagrid,支持远程取数、分页、单行点击。

最终的显示效果类似于:

titlestatuscreatedAtupdatedAt
4-115Sun Dec 25 2016 20:38:18 GMT+0800Sun Dec 25 2016 20:38:18 GMT+0800
4-216Sun Dec 25 2016 20:38:18 GMT+0800Sun Dec 25 2016 20:38:18 GMT+0800
4-317Sun Dec 25 2016 20:38:18 GMT+0800Sun Dec 25 2016 20:38:18 GMT+0800
4-418Sun Dec 25 2016 20:38:18 GMT+0800Sun Dec 25 2016 20:38:18 GMT+0800
4-519Sun Dec 25 2016 20:38:18 GMT+0800Sun Dec 25 2016 20:38:18 GMT+0800

< 1 2 3 4 5 6 ... 20 >

点击任意一行后,将会触发相应的监听器。

Keywords

datagrid

FAQs

Package last updated on 14 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts