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
2
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.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-89.86%
Maintainers
2
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

NameTypeRequireDefaultNote
jsxcolumnsarrayrequirednull表格列配置项,具体见这里
widthnumberoptional1000表格的宽度
heightnumberoptional100%表格的高度
showColumnPickerbooleanoptionaltrue是否显示列筛选按钮
showPagerbooleanoptionaltrue是否显示分页
showHeaderbooleanoptionaltrue是否显示表格头部
showMaskbooleanoptionaltrue是否在 loading 的时候显示蒙层
showSearchbooleanoptionalfalse是否显示内置的搜索栏
headerHeightnumberoptional40表格头部的高度
pageSizenumberoptional10每页显示多少条数据
queryKeysarrayoptional[]有哪些数据会传递给 subComp
jsxdataobjectoptional-在远端数据还没有返回时用作默认数据
fetchUrlstringoptional""表格的数据源
fetchParamsobjectoptional-表格在请求数据时,会额外附带的参数,具有最高的优先级
actionBarobjectoptionalnull表格内置的操作条配置
beforeFetchfunction(data, from)optionalnoop两个参数,data 表示表格请求数据时即将发送的参数,from 表示这次请求数据的行为从哪里产生,内置的有 search(搜索栏),order(排序) & pagination(分页),该函数需要返回值,返回值为真正请求所携带的参数。
processDatafunction(data)optionalnoop有时源返回的数据格式,并不符合 Table 的要求,可以通过此函数进行调整,参数 data 是返回数据中 content 字段的 value,该函数需要返回值,返回值为符合 content 字段 value 的数据结构。
addRowClassNamefunction(rowData)optionalnoop用于为特定的某几行添加特殊的 class,用于样式定制

Tree 模式专用

NameTypeRequireDefaultNote
renderModelstringoptional'tree'render to tree model
levelsnumberoptional1tree model, default expand level number

行内编辑表格专用

NameTypeRequireDefaultNote
onChangefunction(data)optionnoop有表格编辑行为触发,参数的数据格式为 {data: 表格的所有数据, changedData: 变动行的数据, dataKey: xxx, editKey: xxx, pass: 正在编辑的域是否通过校验}

Props you should not define by yourself

Parent will pass this props to his child

props namedefalut ValueNote
passedDatanullData passed from parent

Columns Config

Key NameRequireTypeNote
dataKeyrequiredstringwhich key in data will be shown in view mode
editKeyoptionalstringwhich key in data will be used in edit mode, equal to dataKey if not specified
titlerequiredstringtable head name
widthrequirednumber
hiddenoptionalboolean
orderoptionalbooleanshow the built-in sorter
typeoptionalstringcontaining 'money', 'card', 'cnmobile', 'checkbox', 'action', 'radio', 'text', 'select' & 'custom'
actionsoptionalarraywhen type =='action', we need this attr
customFieldoptionalReact Componentwhen type is 'custom', pass your custom Field extended from CellField to Table
renderoptionalfunctionrender the cell as you want, return a react element
fixedoptionalbooleanset the column fixed or not
delimiteroptionalstringdelimiter used in type 'money', 'card', 'cnmobile' formating
alignoptionalstringtext-align, default: 'left'

let columns = [
        { dataKey: 'check', type: 'checkbox', disable: false}, // custom checkbox column, dataKey can be anyone, true means checked.
        { 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 },
        { 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>
        }}
 ]

Rules

  • return data format here
   {
	"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": ""
	}

the data format above is what server should send. If you pass data via jsxdata, you just need passed the content, like below

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

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

API

Row Editing

  • getData(): return cellData & do Validation
  • addEmptyRow(): add an empty Row in 'edit' mode
  • addRow(rowData): add an row with specified data in 'edit' mode.
  • delRow(rowData): delete specified row by jsxid
  • editRow(rowData): make the specified row in 'edit' mode.
  • viewRow(rowData): make the specified row in 'view' mode.
  • saveRow(rowData): save the row change.
  • resetRow(rowData): cancel the row change before saveRow() is called.

Data Fetching

  • fetchData(from): call this method when you want the table to fetch Data via ajax again.
    • @param from {string} {optional}: this param will be passed to props.beforeFetch.

Other

  • toggleSubComp(rowData): show or hide sub comp

Keywords

FAQs

Package last updated on 17 Dec 2015

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