wix-style-react
Version:
wix-style-react
110 lines (95 loc) • 4.88 kB
JavaScript
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { 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) : subClass.__proto__ = superClass; }
import React from 'react';
import DataTable from 'wix-style-react/DataTable';
import './Example.scss';
var style = {
width: '966px'
};
var baseData = [{ firstName: 'Meghan', lastName: 'Bishop' }, { firstName: 'Sara', lastName: 'Porter' }, { firstName: 'Deborah', lastName: 'Rhodes' }, { firstName: 'Walter', lastName: 'Jenning' }, { firstName: 'Amanda', lastName: 'Woods' }];
var DataTableSortableOldDesignExample = function (_React$Component) {
_inherits(DataTableSortableOldDesignExample, _React$Component);
function DataTableSortableOldDesignExample(props) {
_classCallCheck(this, DataTableSortableOldDesignExample);
var _this = _possibleConstructorReturn(this, (DataTableSortableOldDesignExample.__proto__ || Object.getPrototypeOf(DataTableSortableOldDesignExample)).call(this, props));
_this.state = { sort: {}, data: baseData };
return _this;
}
_createClass(DataTableSortableOldDesignExample, [{
key: 'handleSortClick',
value: function handleSortClick(colNum) {
var desc = !this.state.sort[colNum];
var sort = Object.assign({}, this.state.sort, _defineProperty({}, colNum, desc));
var filelds = {
1: 'firstName',
2: 'lastName'
};
var sortedData = this.sortDataByField(filelds[colNum], desc);
this.setState({ sort: sort, data: sortedData });
}
}, {
key: 'sortDataByField',
value: function sortDataByField(field, desc) {
return this.state.data.sort(function (a, b) {
return desc ? ~~(field ? a[field] < b[field] : a < b) : ~~(field ? a[field] > b[field] : a > b);
}); // eslint-disable-line
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
return React.createElement(
'div',
{ style: style },
React.createElement(DataTable, {
dataHook: 'story-data-table',
data: this.state.data,
onSortClick: function onSortClick(col, colNum) {
return _this2.handleSortClick(colNum);
},
itemsPerPage: 20,
columns: [{
title: 'Row Number',
render: function render(row, rowNum) {
return '#' + (rowNum + 1);
},
width: '20%',
minWidth: '75px',
important: true
}, {
title: 'First Name',
sortable: true,
sortDescending: !!this.state.sort[1],
render: function render(row) {
return React.createElement(
'span',
null,
row.firstName
);
},
width: '40%',
minWidth: '100px'
}, {
title: 'Last Name',
sortable: true,
sortDescending: !!this.state.sort[2],
render: function render(row) {
return React.createElement(
'span',
null,
row.lastName
);
},
width: '40%',
minWidth: '100px'
}]
})
);
}
}]);
return DataTableSortableOldDesignExample;
}(React.Component);
export default DataTableSortableOldDesignExample;