New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

uxcore-table

Package Overview
Dependencies
Maintainers
3
Versions
299
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uxcore-table

table ui component for react

  • 1.3.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-89.86%
Maintainers
3
Weekly downloads
 
Created
Source

uxcore-table


Table UI Component based on React. working for many modes such as sub table, tree table and inline editing table.

How to run

$ git clone https://github.com/uxcore/uxcore-table
$ cd uxcore-table
$ npm install
$ gulp server

Best Practice


	let columns = [
        { dataKey: 'check', type: 'checkbox', disable: false}, // custom checkbox column, dataKey can be anyone, true means checked.
	    { dataKey: 'id', title: 'ID', width: 50,hidden:true},
	    { dataKey: 'country', title:'国家', width: 200,ordered:true},
	    { dataKey: 'city',title:'城市', width: 150,ordered:true },
	    { dataKey: 'firstName',title:"FristName" },  
	    { dataKey: 'lastName' ,title:"LastName"},
	    { dataKey: 'email',title:"Email",width: 200,ordered:true }
	];


	let rowSelection = {
      onSelect: function(record, selected, selectedRows) {
        console.log(record, selected, selectedRows);
      },
      onSelectAll: function(record, data) {
        console.log(record, data);
      }
    };

	renderProps={
        actionBar: {
           'new': function(type, actions){ alert(type); },  // type means 'new' in this line
           'import': function(type, actions){ alert(type); }, // actions contains all table's APIs, such as actions.addEmptyRow()
           'export': function(type, actions){ alert(type); }
        },
        fetchUrl:"http://localhost:3000/demo/data.json",
        jsxcolumns:columns,
        subComp:(<Table {...renderSubProps}  ref="subTable"/>),
        rowSelection: rowSelection
	},
	
	renderSubProps={
        jsxcolumns:columns,
        fetchUrl:"http://localhost:3000/demo/data.json",
        queryKeys:["dataKey","firstName"],
        onModifyRow: this.onModifyRow
	};

	<Table {...renderProps} />

Props

NameTypeRequireDefaultSince Ver.Note
jsxcolumnsarrayrequirednull-表格列配置项,具体见这里
widthnumberoptional1000-表格的宽度
heightnumberoptional100%-表格的高度
showColumnPickerbooleanoptionaltrue-是否显示列筛选按钮
showPagerbooleanoptionaltrue-是否显示分页
showHeaderbooleanoptionaltrue-是否显示表格头部
showHeaderBorderbooleanoptionalfalse1.3.6是否显示头部列之间的分割线
showMaskbooleanoptionaltrue-是否在 loading 的时候显示蒙层
showSearchbooleanoptionalfalse-是否显示内置的搜索栏
doubleClickToEditbooleanoptionaltrue-是否开启双击编辑
emptyTextstring or elementoptional"暂无数据"-当没有数据时 Table 展示的文案
searchBarPlaceholderstringoptional"搜索表格内容"1.3.0searchBar 的占位符
headerHeightnumberoptional40-表格头部的高度
pageSizenumberoptional10-每页显示多少条数据
queryKeysarrayoptional[]-有哪些数据会传递给 subComp
jsxdataobjectoptional--在远端数据还没有返回时用作默认数据
fetchUrlstringoptional""-表格的数据源
fetchParamsobjectoptional--表格在请求数据时,会额外附带的参数,具有最高的优先级
actionBarobject/arrayoptionalnull-表格内置的操作条配置,详细见此
beforeFetchfunction(data, from)optionalnoop-两个参数,data 表示表格请求数据时即将发送的参数,from 表示这次请求数据的行为从哪里产生,内置的有 search(搜索栏),order(排序) & pagination(分页),该函数需要返回值,返回值为真正请求所携带的参数。
processDatafunction(data)optionalnoop-有时源返回的数据格式,并不符合 Table 的要求,可以通过此函数进行调整,参数 data 是返回数据中 content 字段的 value,该函数需要返回值,返回值为符合 content 字段 value 的数据结构。
onFetchErrorfunction(result)optionalnoop1.3.7在返回数据中 success 不是 true 的情况下触发,返回所有请求得到的数据
addRowClassNamefunction(rowData)optionalnoop-用于为特定的某几行添加特殊的 class,用于样式定制
rowSelectionobjectoptionalnoop-选中复选框时触发的回调,rowSelection 是由回调函数组成的对象,包括 onSelect 和 onSelectAll,例子见此

折叠展开专用

NameTypeRequireSince Ver.DefaultNote
SubCompReact Elementoptional--传入二级组件

Tree 模式专用

NameTypeRequireSince Ver.DefaultNote
renderModelstringoptional-''使用 tree 模式时,此项为 'tree'
levelsnumberoptional-1tree 模式默认展开的级数

行内编辑表格专用

NameTypeRequireSince Ver.DefaultNote
onChangefunction(data)optional-noop有表格编辑行为触发,参数的数据格式为 {data: 表格的所有数据, changedData: 变动行的数据, dataKey: xxx, editKey: xxx, pass: 正在编辑的域是否通过校验}
getSavedDatabooleanoptional-trueonChange 中的数据是否是保存之后的数据(通过了 saveRow() 的数据)

列配置项(jsxcolumns)

Key NameTypeSince Ver.RequireNote
dataKeystring-required表格的数据中用于查看模式展示的字段
editKeystring-optional表格的数据中用于编辑模式的字段,如对于 select 来说,此项应为选项里的 key
titlestring-required列头
widthnumber-required列宽
hiddenboolean-optional是否隐藏,默认为 false
orderboolean-optional是否显示内置的排序,默认为 false
typestring-optional包含 'money', 'card', 'cnmobile', 'checkbox', 'action', 'radio', 'text', 'select' 和 'custom'
actionsarray-optional当 type 是 action 的时候会用到,用于定义具体有哪些操作,格式见下方说明
customFieldReact Element-optional当 type 是 custom 的时候会用到,用于传入自定义的 Field,用于行内编辑
renderfunction-optional在查看模式下,用户定制渲染的方式,返回一个 jsx 格式
fixedboolean-optional是否为固定列
delimiterstring-optional在 type 是 'money', 'card', 'cnmobile' 的时候会用到,用于传入格式化的分隔符
alignstring-optional文字居中方式,默认 'left'
disableboolean-optional在 type 为 checkbox 时使用,是否禁用 checkbox,优先级高于 isDisable
isDisablefunction(rowData)1.3.1optional在 tpye 为 checkbox 时使用,为一个回调函数,用于根据 rowData 去判断是否禁用该行的 checkbox
canEditfunction(rowData)1.3.3optional在 type 为可编辑表格的类别时使用,为一个回调函数,用于根据 rowData 去判断该行该列是否可以编辑

列配置项的例子


let columns = [
        { dataKey: 'check', type: 'checkbox', isDisable: function(rowData) {return /city/.test(rowData.city)}}, // 定制 checkbox 列,dataKey 对应的应是一个 bool 值,表明是否被选中。
        { dataKey: 'country', title:'国家', width: 200,ordered:true},
        { dataKey: 'action1', title:'操作1', width:100, type:"action",actions: [
            {
                title: '编辑',
                callback: (rowData) => {
                    me.refs.grid.editRow(rowData);
                },
                mode: Constants.MODE.VIEW
            },
            {
                title: '保存',
                callback: (rowData) => {
                    me.refs.grid.saveRow(rowData);
                },
                mode: Constants.MODE.EDIT
            }
        ]},
        { dataKey: 'action', title:'链接', width:100, render: function(cellData,rowData) {
            return <div><a href="#">{rowData.email}</a></div>
        }}
 ]

列配置项的例子2(带列群组, since ver. 1.3.0)


let columns = [
        { dataKey: 'check', type: 'checkbox', disable: false}, // custom checkbox column, dataKey can be anyone, true means checked.
        {
            group: "国家",
            columns: [
                { dataKey: 'country', title:'国家', width: 200,ordered:true},
                { dataKey: 'country2', title:'国家2', width: 200,ordered:true},
            ]
        }
 ]

rowSelection 的例子


let rowSelection = {
      onSelect: function(record, selected, selectedRows) {
          console.log(record, selected, selectedRows);
      },
      onSelectAll: function(record, data) {
          console.log(record, data);
      }
};

返回的数据格式

  • 数据格式的约定见此
   {
	"content":{
		"data":[
			{	
				"id":'1'
				"grade":"grade1",
				"email":"email1",
				"firstName":"firstName1",
				"lastName":"lastName1",
				"birthDate":"birthDate1",
				"country":"country1",
				"city":"city1"
			}
			...
	
		],
		"currentPage":1,
		"totalCount":30
	},
	"success": true,
	"errorCode": "",
	"errorMsg": ""
	}

上面的数据格式是 ajax 返回的数据格式要求,如果你通过 jsxdata 传值,只需要 content 里面的内容。

{
    "data":[
        {   
            "id":'1'
            "grade":"grade1",
            "email":"email1",
            "firstName":"firstName1",
            "lastName":"lastName1",
            "birthDate":"birthDate1",
            "country":"country1",
            "city":"city1"
        }
        ...

    ],
    "currentPage":1,
    "totalCount":30
}

ActionBar 配置的例子


// actionBar 支持传入一个对象
actionBar: {
    "新增行": () => { // 点击回调
        me.refs.grid.addEmptyRow();
    },
    "编辑所有行": () => {
        me.refs.grid.editAllRow();
    }
}

// 或者定制能力更加强大的数组
actionBar: [
    {
        title: '新增行', // 显示名称
        callback: () => { // 点击回调
            me.refs.grid.addEmptyRow();
        },
        render: (title) => { // 定制渲染
            return <Button>{title}</Button>
        }
    },
    {
        title: "编辑所有行",
        callback: () => {
            me.refs.grid.editAllRow();
        }
    },
    {
        title: "保存所有行",
        callback: () => {
            me.refs.grid.saveAllRow();
        }
    }
    
]

actions 配置的例子

actions: [
    {
        title: '编辑', // 操作名称
        callback: (rowData) => { // 操作回调
            me.refs.grid.editRow(rowData);
        },
        mode: Constants.MODE.VIEW // 非必要参数,只在何种模式下显示
    },
    {
        title: '保存',
        callback: (rowData) => {
            me.refs.grid.saveRow(rowData);
        },
        mode: Constants.MODE.EDIT,
        render: (title, rowData) => { // 定制渲染
            return title + '1'
        }
    }
]

API

行内编辑用

  • getData(): 返回表格的数据,并作校验。
  • addEmptyRow(): 添加一个空的新行。
  • addRow(rowData): 以指定数据添加一个新行。
  • delRow(rowData): 删除一个新行。
  • editRow(rowData): 使指定的行切换到编辑模式。
  • editAllRow(): 使所有行切换到编辑模式。
  • viewRow(rowData): 使指定的行切换到查看模式。
  • saveRow(rowData): 保存行的数据(同时切换至查看模式)。
  • saveAllRow(): 保存所有行的数据(同时切换至查看模式)。
  • resetRow(rowData): 重置行到数据(若保存过,则为保存过后的数据)。

获取数据

  • fetchData(from): 使表格重新请求一次数据。
    • @param from {string} {optional}: 这个参数会传入到 beforeFetch 的回调中。

其他

  • toggleSubComp(rowData): 使指定的行显示或隐藏二级组件(subComp)。

Keywords

FAQs

Package last updated on 29 Feb 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc