npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

antd-datagrid

v0.3.5

Published

datagrid use antd

Downloads

27

Readme

发布

> 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,支持远程取数、分页、单行点击。

最终的显示效果类似于:

title | status | createdAt | updatedAt -------|--------|-----------------------------------|------------- 4-1 | 15 | Sun Dec 25 2016 20:38:18 GMT+0800 | Sun Dec 25 2016 20:38:18 GMT+0800 4-2 | 16 | Sun Dec 25 2016 20:38:18 GMT+0800 | Sun Dec 25 2016 20:38:18 GMT+0800 4-3 | 17 | Sun Dec 25 2016 20:38:18 GMT+0800 | Sun Dec 25 2016 20:38:18 GMT+0800 4-4 | 18 | Sun Dec 25 2016 20:38:18 GMT+0800 | Sun Dec 25 2016 20:38:18 GMT+0800 4-5 | 19 | Sun Dec 25 2016 20:38:18 GMT+0800 | Sun Dec 25 2016 20:38:18 GMT+0800

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

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