Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持传入pageSize和currentPage来设定初始分页模式 #60

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions docs/en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Supported attributes of `Element UI Table`: stripe / border / height / max-heigh
| render | function to handle data, and show the return value. The function will have the element of list data as parameter | function | - | - |
| slotName | use slot to wrap a code block to build column content | string | - | - |
| type | Supported after version`0.4.28`. This is a supported property on Element UI Table. We try to use this property to distinguish adding slot content to column or not, so that we can support new features but keep the compabilities. Without setting this property, we will keep same behavior as the previous version, which will take certain column definitions and pass to Element UI Table Column object, and we will handle some custom functions such as `render`, `formatter`, etc. But when this property has been set with a value, we will simply pass anything from column defintion to Element UI Table Column. In this way, we can also support multi selection feature, index col feature, etc. Setting `type` to `default` will also let Element UI Table Column take over the rendering which will simply take `prop` from data object with `filter` setting considered. | string | default/selection/index/expand | |
| page-size | Size of each page, `sync` decoration is supported | Number | | |
| current-page | Current page index, start from 1, same logic as the original `el-pagination` componenet, `sync` decoration is supported | | | |

PS: Also support more attributes, please refer to Element UI [Table column Attribute](https://github.com/ElemeFE/element/blob/dev/examples/docs/en-US/table.md#table-column-attributes)。

Expand Down
2 changes: 2 additions & 0 deletions docs/zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
| page-index-key | 参数:页码数 的 key 值 | string | - | pageIndex |
| page-size-key | 参数:每页展示个数 的 key 值 | string | - | pageSize |
| table-style | 传递给`el-table`的样式style | string | - | width:100%;margin-top:20px; |
| page-size | 每页条数,支持`sync`修饰符 | Number | | |
| current-page | 当前页码,逻辑同`el-pagination`组件,支持`sync`修饰符 | Number | | |

注:更多属性,请参考 Element UI [Table 组件的文档](https://github.com/ElemeFE/element/blob/dev/examples/docs/zh-CN/table.md#table-attributes)。

Expand Down
37 changes: 30 additions & 7 deletions lib/el-search-table-pagination.common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* el-search-table-pagination
* Copyright(c) 2017 - 2019 zollero
* Copyright(c) 2017 - 2021 zollero
* MIT Licensed
*/
module.exports =
Expand Down Expand Up @@ -419,7 +419,7 @@ exports.default = _main2.default;
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_aae06b82_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__ = __webpack_require__(12);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_706605f1_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__ = __webpack_require__(12);
var normalizeComponent = __webpack_require__(0)
/* script */

Expand All @@ -435,7 +435,7 @@ var __vue_scopeId__ = null
var __vue_module_identifier__ = null
var Component = normalizeComponent(
__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default.a,
__WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_aae06b82_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__["a" /* default */],
__WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_706605f1_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__["a" /* default */],
__vue_template_functional__,
__vue_styles__,
__vue_scopeId__,
Expand Down Expand Up @@ -615,8 +615,8 @@ exports.default = {
return {
Vue: _vue2.default,
pagination: {
pageIndex: 1,
pageSize: function () {
pageIndex: this.currentPage || 1,
pageSize: this.pageSize || function () {
var pageSizes = _this.pageSizes;

if (pageSizes.length > 0) {
Expand All @@ -640,10 +640,12 @@ exports.default = {
methods: {
handleSizeChange: function handleSizeChange(size) {
this.pagination.pageSize = size;
this.$emit('update:pageSize', size);
this.dataChangeHandler();
},
handleCurrentChange: function handleCurrentChange(pageIndex) {
this.pagination.pageIndex = pageIndex;
this.$emit('update:currentPage', pageIndex);
this.dataChangeHandler();
},
searchHandler: function searchHandler() {
Expand Down Expand Up @@ -859,6 +861,18 @@ exports.default = {
watch: {
data: function data(value) {
this.loadLocalData(value);
},

currentPage: function currentPage(val) {
if (val) {
this.pagination.pageIndex = val;
}
},

pageSize: function pageSize(val) {
if (val) {
this.pagination.pageSize = val;
}
}
}
};
Expand Down Expand Up @@ -1052,7 +1066,16 @@ var props = {
pageSizeKey: {
type: String,
default: 'pageSize'
}
},
pageSize: {
type: [Number, null],
default: null
},
currentPage: {
type: [Number, null],
default: null
},
cellClassName: [String, Function]

// Object.keys(formProps).forEach(v => {
// props.formOptions[v] = formProps[v]
Expand Down Expand Up @@ -1339,7 +1362,7 @@ var esExports = { render: render, staticRenderFns: staticRenderFns }
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[(_vm.formOptions)?_c('search-form',{ref:"searchForm",attrs:{"forms":_vm.formOptions.forms,"size":_vm.formOptions.size,"fuzzy":_vm.formOptions.fuzzy,"inline":_vm.formOptions.inline,"label-width":_vm.formOptions.labelWidth,"item-width":_vm.formOptions.itemWidth,"submit-handler":_vm.searchHandler,"submit-loading":_vm.loading,"showResetBtn":_vm.formOptions.showResetBtn,"submitBtnText":_vm.formOptions.submitBtnText,"resetBtnText":_vm.formOptions.resetBtnText,"resetBtnCallback":_vm.formOptions.resetBtnCallback}}):_vm._e(),_vm._t("form",null,{loading:_vm.loading,search:_vm.searchHandler}),_vm._t("default"),_c('el-table',{directives:[{name:"loading",rawName:"v-loading.lock",value:(_vm.loading),expression:"loading",modifiers:{"lock":true}}],ref:"table",style:(_vm.tableStyle),attrs:{"data":_vm.tableData,"border":_vm.border,"size":_vm.size,"stripe":_vm.stripe,"height":_vm.height,"max-height":_vm.maxHeight,"fit":_vm.fit,"show-header":_vm.showHeader,"highlight-current-row":_vm.highlightCurrentRow,"current-row-key":_vm.currentRowKey,"row-class-name":_vm.rowClassName,"row-style":_vm.rowStyle,"row-ket":_vm.rowKey,"empty-text":_vm.emptyText,"default-expand-all":_vm.defaultExpandAll,"expand-row-keys":_vm.expandRowKeys,"default-sort":_vm.defaultSort,"tooltip-effect":_vm.tooltipEffect,"show-summary":_vm.showSummary,"sum-text":_vm.sumText,"summary-method":_vm.summaryMethod},on:{"select":function (selection, row) { return _vm.emitEventHandler('select', selection, row); },"select-all":function (selection) { return _vm.emitEventHandler('select-all', selection); },"selection-change":function (selection) { return _vm.emitEventHandler('selection-change', selection); },"cell-mouse-enter":function (row, column, cell, event) { return _vm.emitEventHandler('cell-mouse-enter', row, column, cell, event); },"cell-mouse-leave":function (row, column, cell, event) { return _vm.emitEventHandler('cell-mouse-leave', row, column, cell, event); },"cell-click":function (row, column, cell, event) { return _vm.emitEventHandler('cell-click', row, column, cell, event); },"cell-dblclick":function (row, column, cell, event) { return _vm.emitEventHandler('cell-dblclick', row, column, cell, event); },"row-click":function (row, event, column) { return _vm.emitEventHandler('row-click', row, event, column); },"row-dblclick":function (row, event) { return _vm.emitEventHandler('row-dblclick', row, event); },"row-contextmenu":function (row, event) { return _vm.emitEventHandler('row-contextmenu', row, event); },"header-click":function (column, event) { return _vm.emitEventHandler('header-click', column, event); },"sort-change":function (args) { return _vm.emitEventHandler('sort-change', args); },"filter-change":function (filters) { return _vm.emitEventHandler('filter-change', filters); },"current-change":function (currentRow, oldCurrentRow) { return _vm.emitEventHandler('current-change', currentRow, oldCurrentRow); },"header-dragend":function (newWidth, oldWidth, column, event) { return _vm.emitEventHandler('header-dragend', newWidth, oldWidth, column, event); },"expand-change":function (row, expanded) { return _vm.emitEventHandler('expand-change', row, expanded); }}},[_vm._t("prepend"),_vm._l((_vm.columns),function(column,columnIndex){return [(column.type === undefined)?_c('el-table-column',{key:columnIndex,attrs:{"column-key":column.columnKey,"prop":column.prop,"label":column.label,"width":column.minWidth ? '-' : (column.width || 140),"minWidth":column.minWidth || column.width || 140,"fixed":column.fixed,"render-header":column.renderHeader,"sortable":column.sortable,"sort-by":column.sortBy,"sort-method":column.method,"resizable":column.resizable,"formatter":column.formatter,"show-overflow-tooltip":column.showOverflowTooltip,"align":column.align,"header-align":column.headerAlign || column.align,"class-name":column.className,"label-class-name":column.labelClassName,"selectable":column.selectable,"reserve-selection":column.reserveSelection,"filters":column.filters,"filter-placement":column.filterPlacement,"filter-multiple":column.filterMultiple,"filter-method":column.filterMethod,"filtered-value":column.filteredValue},scopedSlots:_vm._u([{key:"default",fn:function(scope){return [(column.filter)?_c('span',[_vm._v("\n "+_vm._s(_vm.Vue.filter(column['filter'])(scope.row[column.prop]))+"\n ")]):(column.slotName)?_c('span',[_vm._t(column.slotName,null,{row:scope.row,$index:scope.$index})],2):(column.render)?_c('span',[_vm._v("\n "+_vm._s(column.render(scope.row))+"\n ")]):(column.formatter)?_c('span',[_vm._v("\n "+_vm._s(column.formatter(scope.row, scope.column, scope.row[column.prop], scope.$index))+"\n ")]):_c('span',[_vm._v("\n "+_vm._s(scope.row[column.prop])+"\n ")])]}}])}):_c('el-table-column',_vm._b({key:columnIndex},'el-table-column',column,false))]}),_vm._t("append")],2),(_vm.showPagination)?_c('div',{staticStyle:{"margin-top":"10px","text-align":"right"}},[_c('el-pagination',{attrs:{"current-page":_vm.pagination.pageIndex,"page-sizes":_vm.pageSizes,"page-size":_vm.pagination.pageSize,"layout":_vm.paginationLayout,"total":_vm.total},on:{"size-change":_vm.handleSizeChange,"current-change":_vm.handleCurrentChange}})],1):_vm._e()],2)}
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[(_vm.formOptions)?_c('search-form',{ref:"searchForm",attrs:{"forms":_vm.formOptions.forms,"size":_vm.formOptions.size,"fuzzy":_vm.formOptions.fuzzy,"inline":_vm.formOptions.inline,"label-width":_vm.formOptions.labelWidth,"item-width":_vm.formOptions.itemWidth,"submit-handler":_vm.searchHandler,"submit-loading":_vm.loading,"showResetBtn":_vm.formOptions.showResetBtn,"submitBtnText":_vm.formOptions.submitBtnText,"resetBtnText":_vm.formOptions.resetBtnText,"resetBtnCallback":_vm.formOptions.resetBtnCallback}}):_vm._e(),_vm._t("form",null,{loading:_vm.loading,search:_vm.searchHandler}),_vm._t("default"),_c('el-table',{directives:[{name:"loading",rawName:"v-loading.lock",value:(_vm.loading),expression:"loading",modifiers:{"lock":true}}],ref:"table",style:(_vm.tableStyle),attrs:{"data":_vm.tableData,"border":_vm.border,"size":_vm.size,"stripe":_vm.stripe,"height":_vm.height,"max-height":_vm.maxHeight,"fit":_vm.fit,"show-header":_vm.showHeader,"highlight-current-row":_vm.highlightCurrentRow,"current-row-key":_vm.currentRowKey,"row-class-name":_vm.rowClassName,"cell-class-name":_vm.cellClassName,"row-style":_vm.rowStyle,"row-ket":_vm.rowKey,"empty-text":_vm.emptyText,"default-expand-all":_vm.defaultExpandAll,"expand-row-keys":_vm.expandRowKeys,"default-sort":_vm.defaultSort,"tooltip-effect":_vm.tooltipEffect,"show-summary":_vm.showSummary,"sum-text":_vm.sumText,"summary-method":_vm.summaryMethod},on:{"select":function (selection, row) { return _vm.emitEventHandler('select', selection, row); },"select-all":function (selection) { return _vm.emitEventHandler('select-all', selection); },"selection-change":function (selection) { return _vm.emitEventHandler('selection-change', selection); },"cell-mouse-enter":function (row, column, cell, event) { return _vm.emitEventHandler('cell-mouse-enter', row, column, cell, event); },"cell-mouse-leave":function (row, column, cell, event) { return _vm.emitEventHandler('cell-mouse-leave', row, column, cell, event); },"cell-click":function (row, column, cell, event) { return _vm.emitEventHandler('cell-click', row, column, cell, event); },"cell-dblclick":function (row, column, cell, event) { return _vm.emitEventHandler('cell-dblclick', row, column, cell, event); },"row-click":function (row, event, column) { return _vm.emitEventHandler('row-click', row, event, column); },"row-dblclick":function (row, event) { return _vm.emitEventHandler('row-dblclick', row, event); },"row-contextmenu":function (row, event) { return _vm.emitEventHandler('row-contextmenu', row, event); },"header-click":function (column, event) { return _vm.emitEventHandler('header-click', column, event); },"sort-change":function (args) { return _vm.emitEventHandler('sort-change', args); },"filter-change":function (filters) { return _vm.emitEventHandler('filter-change', filters); },"current-change":function (currentRow, oldCurrentRow) { return _vm.emitEventHandler('current-change', currentRow, oldCurrentRow); },"header-dragend":function (newWidth, oldWidth, column, event) { return _vm.emitEventHandler('header-dragend', newWidth, oldWidth, column, event); },"expand-change":function (row, expanded) { return _vm.emitEventHandler('expand-change', row, expanded); }}},[_vm._t("prepend"),_vm._l((_vm.columns),function(column,columnIndex){return [(column.type === undefined)?_c('el-table-column',{key:columnIndex,attrs:{"column-key":column.columnKey,"prop":column.prop,"label":column.label,"width":column.minWidth ? '-' : (column.width || 140),"minWidth":column.minWidth || column.width || 140,"fixed":column.fixed,"render-header":column.renderHeader,"sortable":column.sortable,"sort-by":column.sortBy,"sort-method":column.method,"resizable":column.resizable,"formatter":column.formatter,"show-overflow-tooltip":column.showOverflowTooltip,"align":column.align,"header-align":column.headerAlign || column.align,"class-name":column.className,"label-class-name":column.labelClassName,"selectable":column.selectable,"reserve-selection":column.reserveSelection,"filters":column.filters,"filter-placement":column.filterPlacement,"filter-multiple":column.filterMultiple,"filter-method":column.filterMethod,"filtered-value":column.filteredValue},scopedSlots:_vm._u([{key:"default",fn:function(scope){return [(column.filter)?_c('span',[_vm._v("\n "+_vm._s(_vm.Vue.filter(column['filter'])(scope.row[column.prop]))+"\n ")]):(column.slotName)?_c('span',[_vm._t(column.slotName,null,{row:scope.row,$index:scope.$index})],2):(column.render)?_c('span',[_vm._v("\n "+_vm._s(column.render(scope.row))+"\n ")]):(column.formatter)?_c('span',[_vm._v("\n "+_vm._s(column.formatter(scope.row, scope.column, scope.row[column.prop], scope.$index))+"\n ")]):_c('span',[_vm._v("\n "+_vm._s(scope.row[column.prop])+"\n ")])]}}])}):_c('el-table-column',_vm._b({key:columnIndex},'el-table-column',column,false))]}),_vm._t("append")],2),(_vm.showPagination)?_c('div',{staticStyle:{"margin-top":"10px","text-align":"right"}},[_c('el-pagination',{attrs:{"current-page":_vm.pagination.pageIndex,"page-sizes":_vm.pageSizes,"page-size":_vm.pagination.pageSize,"layout":_vm.paginationLayout,"total":_vm.total},on:{"size-change":_vm.handleSizeChange,"current-change":_vm.handleCurrentChange}})],1):_vm._e()],2)}
var staticRenderFns = []
var esExports = { render: render, staticRenderFns: staticRenderFns }
/* harmony default export */ __webpack_exports__["a"] = (esExports);
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js

Large diffs are not rendered by default.

Loading