console
const $gridManager = window.GridManager.default;
let allData = [];
const setAllData = function(tableNum, dataNum) {
allData = [];
for (let i = 0; i<= tableNum; i++) {
const data = [];
for(let j=0;j<dataNum;j++){
data.push({
"id": i,
"name": `test-${i}`,
"age": "28",
"createDate": "2015-03-12",
"info": "野生前端程序"
});
}
allData.push(data);
}
}
const getBlogList = function(index) {
const data = allData[index] || [];
return new Promise((resolve, reject) => {
resolve({
data,
totals: data.length
});
});
};
const getTableOptions = tableNum => {
const list = [];
for(let i=0;i <tableNum;i++){
list.push({
supportRemind: true,
gridManagerName: 'test' + i + new Date().getTime(),
height: '200px',
supportAjaxPage: true,
ajaxData: () => {
return getBlogList(i);
},
ajaxType: 'POST',
supportMenu: true,
query: {test: 22},
pageSize: 30,
emptyTemplate: settings => {
const emptyText = settings.query.title ? '搜索结果为空' : '这个Vue表格, 什么数据也没有';
return `<section style="text-align: center">${emptyText}</section>`;
},
columnData: [
{
key: 'name',
remind: 'the username',
sorting: 'up',
width: '200px',
text: 'username'
},{
key: 'age',
remind: 'the age',
sorting: '',
width: '200px',
text: 'age'
},{
key: 'info',
remind: 'the info',
sorting: '',
text: 'info'
},{
key: 'createDate',
text: '创建时间',
remind: 'the createDate',
sorting: 'down',
width: '200px',
fixed: 'right'
},{
key: 'operation',
remind: '修改创建时间',
sorting: '',
width: '130px',
text: '修改创建时间',
align: 'center',
fixed: 'right',
template: function(operation, rowObject){
return `<span class="plugin-action">修改</span>`;
}
}
]
});
}
return list;
}
let now = Date.now();
const app = new Vue({
el: '#app',
data: {
formData: {
tableNum: 2,
dataNum: 1
},
tableList: null
},
created: function () {
setAllData(this.formData.tableNum, this.formData.dataNum);
this.tableList = getTableOptions(this.formData.tableNum);
},
methods: {
editRow: function (row, index) {
row.title = row.title + ' (编辑于' + new Date().toLocaleDateString() +') ';
row.lastDate = new Date().getTime();
$gridManager.updateRowData('test', 'id', row);
},
actionAlert: function() {
alert('操作栏th是由vue模板渲染的');
},
onSearch() {
setAllData(this.formData.tableNum, this.formData.dataNum);
this.tableList = [];
setTimeout(() => {
this.tableList = getTableOptions(this.formData.tableNum);
});
},
onReset: function () {
this.formData.tableNum = 1;
this.formData.dataNum = 1;
}
}
});
<div id="app" style="min-width:800px;height: 100%">
<section class="search-area">
<div class="sa-ele">
<label class="se-title">表格数:</label>
<input class="se-con" v-model="formData.tableNum"/>
</div>
<div class="sa-ele">
<label class="se-title">行数:</label>
<input class="se-con" v-model="formData.dataNum"/>
</div>
<div class="sa-ele">
<button class="search-action" @click="onSearch()">搜索</button>
<button class="reset-action" @click="onReset()">重置</button>
</div>
</section>
<section class="grid-main">
<div v-if="tableList" style="height: 100%" v-for="(option, index) in tableList">
<grid-manager v-bind:option="option" key="option.gridManagerName"></grid-manager>
</div>
</section>
</div>
html, body{
width: 100%;
height: 100%;
overflow-x:hidden;
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
table .plugin-action{
display: inline-block;
color: steelblue;
margin-right: 10px;
cursor: pointer;
text-decoration: none;
}
table .plugin-action:hover{
text-decoration: underline;
}
.search-area{
height: 50px;
padding: 10px 20px;
border: 1px solid #ccc;
background: #efefef;
margin: 0 10px 15px 10px;
}
.search-area .sa-ele{
display: inline-block;
margin-right: 20px;
font-size: 12px;
}
.search-area .sa-ele .se-title{
display: inline-block;
margin-right: 10px;
}
.search-area .sa-ele .se-con{
display: inline-block;
width:180px;
height: 24px;
border: 1px solid #ccc;
padding: 0 4px;
line-height: 24px;
}
.search-area .sa-ele .search-action, .search-area .sa-ele .reset-action{
display: inline-block;
width:80px;
height: 26px;
border: 1px solid #ccc;
background: #e8e8e8;
padding: 0 4px;
line-height: 26px;
text-align: center;
cursor: pointer;
margin-right: 10px;
}
.search-area .sa-ele .search-action:hover, .search-area .sa-ele .reset-action:hover{
opacity: 0.7;
}
.grid-main {
margin: 10px;
overflow: auto;
}
.grid-main >div{
margin-bottom: 14px;
}