Merge branch 'master' of github.com:tinper-bee/bee-table
This commit is contained in:
commit
13be4cb5d0
|
@ -0,0 +1,134 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||||
|
|
||||||
|
var _react = require("react");
|
||||||
|
|
||||||
|
var _react2 = _interopRequireDefault(_react);
|
||||||
|
|
||||||
|
var _beeIcon = require("bee-icon");
|
||||||
|
|
||||||
|
var _beeIcon2 = _interopRequireDefault(_beeIcon);
|
||||||
|
|
||||||
|
var _beeSelect = require("bee-select");
|
||||||
|
|
||||||
|
var _beeSelect2 = _interopRequireDefault(_beeSelect);
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||||
|
|
||||||
|
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||||
|
|
||||||
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
|
||||||
|
|
||||||
|
var SelectRender = function (_Component) {
|
||||||
|
_inherits(SelectRender, _Component);
|
||||||
|
|
||||||
|
function SelectRender() {
|
||||||
|
var _temp, _this, _ret;
|
||||||
|
|
||||||
|
_classCallCheck(this, SelectRender);
|
||||||
|
|
||||||
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||||
|
args[_key] = arguments[_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = {
|
||||||
|
value: _this.props.value,
|
||||||
|
editable: false
|
||||||
|
}, _this.handleChange = function (e) {
|
||||||
|
var value = e;
|
||||||
|
var self = _this;
|
||||||
|
if (self.props.onChange) {
|
||||||
|
self.props.onChange(value);
|
||||||
|
}
|
||||||
|
_this.setState({ value: value });
|
||||||
|
setTimeout(function () {
|
||||||
|
self.setState({ editable: false });
|
||||||
|
}, 0);
|
||||||
|
}, _this.check = function () {
|
||||||
|
_this.setState({ editable: false });
|
||||||
|
if (_this.props.onChange) {
|
||||||
|
_this.props.onChange(_this.state.value);
|
||||||
|
}
|
||||||
|
}, _this.edit = function () {
|
||||||
|
_this.setState({ editable: true });
|
||||||
|
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectRender.prototype.render = function render() {
|
||||||
|
var _state = this.state,
|
||||||
|
value = _state.value,
|
||||||
|
editable = _state.editable;
|
||||||
|
var isclickTrigger = this.props.isclickTrigger;
|
||||||
|
|
||||||
|
var cellContent = "";
|
||||||
|
if (editable) {
|
||||||
|
cellContent = isclickTrigger ? _react2["default"].createElement(
|
||||||
|
"div",
|
||||||
|
{ className: "editable-cell-input-wrapper" },
|
||||||
|
_react2["default"].createElement(
|
||||||
|
_beeSelect2["default"],
|
||||||
|
_extends({}, this.props, {
|
||||||
|
value: this.state.value,
|
||||||
|
onChange: this.handleChange
|
||||||
|
}),
|
||||||
|
this.props.children
|
||||||
|
),
|
||||||
|
_react2["default"].createElement(_beeIcon2["default"], {
|
||||||
|
type: "uf-correct",
|
||||||
|
className: "editable-cell-icon-check",
|
||||||
|
onClick: this.check
|
||||||
|
})
|
||||||
|
) : _react2["default"].createElement(
|
||||||
|
"div",
|
||||||
|
{ className: "editable-cell-input-wrapper" },
|
||||||
|
_react2["default"].createElement(
|
||||||
|
_beeSelect2["default"],
|
||||||
|
_extends({}, this.props, {
|
||||||
|
value: this.state.value,
|
||||||
|
onChange: this.handleChange
|
||||||
|
}),
|
||||||
|
this.props.children
|
||||||
|
),
|
||||||
|
_react2["default"].createElement(_beeIcon2["default"], {
|
||||||
|
type: "uf-correct",
|
||||||
|
className: "editable-cell-icon-check",
|
||||||
|
onClick: this.check
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
cellContent = isclickTrigger ? _react2["default"].createElement(
|
||||||
|
"div",
|
||||||
|
{ className: "editable-cell-text-wrapper", onClick: this.edit },
|
||||||
|
value || " "
|
||||||
|
) : _react2["default"].createElement(
|
||||||
|
"div",
|
||||||
|
{ className: "editable-cell-text-wrapper" },
|
||||||
|
value || " ",
|
||||||
|
_react2["default"].createElement(_beeIcon2["default"], {
|
||||||
|
type: "uf-pencil",
|
||||||
|
className: "editable-cell-icon",
|
||||||
|
onClick: this.edit
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _react2["default"].createElement(
|
||||||
|
"div",
|
||||||
|
{ className: "editable-cell" },
|
||||||
|
cellContent
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return SelectRender;
|
||||||
|
}(_react.Component);
|
||||||
|
|
||||||
|
exports["default"] = SelectRender;
|
||||||
|
module.exports = exports["default"];
|
File diff suppressed because one or more lines are too long
|
@ -1,20 +1,30 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Table from "../../src";
|
import Table from "../../src";
|
||||||
|
|
||||||
|
//创建新列存放 “合计” 字段
|
||||||
|
let columns2 = {};
|
||||||
|
columns2 = {
|
||||||
|
title: "合计",
|
||||||
|
key: "showSum",
|
||||||
|
dataIndex: "showSum",
|
||||||
|
width: "5%"
|
||||||
|
}
|
||||||
|
|
||||||
var Sum = (Table)=>{
|
var Sum = (Table)=>{
|
||||||
class SumTable extends React.Component{
|
class SumTable extends React.Component{
|
||||||
//无状态
|
//无状态
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentData = ()=>{
|
currentTitle = ()=>{
|
||||||
return <div>{this.props.title}</div>;
|
return <div>{this.props.title}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//合计数字列
|
//合计数字列,并将计算所得数据存储到一个obj对象中
|
||||||
currentData2 = () =>{
|
currentFooter = () =>{
|
||||||
let data_2 = this.props.data;
|
let data_2 = this.props.data;
|
||||||
|
//用一个对象存储合计数据,这里合计对象的属性对应每列字段
|
||||||
let obj ={};
|
let obj ={};
|
||||||
if(Array.isArray(data_2)){
|
if(Array.isArray(data_2)){
|
||||||
for(let i =0;i<data_2.length;i++){
|
for(let i =0;i<data_2.length;i++){
|
||||||
|
@ -33,21 +43,36 @@ var Sum = (Table)=>{
|
||||||
}
|
}
|
||||||
//加key
|
//加key
|
||||||
obj.key = 'sumData';
|
obj.key = 'sumData';
|
||||||
|
//设置新建列的名称
|
||||||
|
obj.showSum = "合计"
|
||||||
|
obj =[obj];
|
||||||
|
//添加合计行
|
||||||
|
let columns_sum = this.props.columns;
|
||||||
|
//针对多选除去多选框,即第一列,换为新建的列
|
||||||
|
this.props.columns[0].dataIndex == "checkbox"?columns_sum[0] = columns2:columns_sum.unshift(columns2);
|
||||||
|
console.log(columns_sum)
|
||||||
|
//除去列为特殊渲染的,避免像a标签这种html代码写入到合计中
|
||||||
|
columns_sum = columns_sum.map((item,index)=>{
|
||||||
|
if(typeof item.render == "function"){
|
||||||
|
delete item.render;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
|
||||||
return <Table
|
return <Table
|
||||||
showHeader={false}
|
showHeader={false}
|
||||||
columns={this.props.columns}
|
columns={columns_sum}
|
||||||
data={[obj]}
|
data={obj}
|
||||||
heji={true}
|
heji={true}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return <Table
|
return <Table
|
||||||
columns={this.props.columns}
|
columns={this.props.columns}
|
||||||
data={this.props.data}
|
data={this.props.data}
|
||||||
heji={true}
|
heji={true}
|
||||||
title={this.currentData}
|
title={this.currentTitle}
|
||||||
footer={this.currentData2}
|
footer={this.currentFooter}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue