基於 Vue 的 GridManager 封裝, 用於便捷的在 Vue 中使用GridManager. 除過Vue特性外,其它API與GridManager API相同。
該文檔爲原生GridManager的文檔,vue版本除了在columnData.text
columnData.template
topFullColumn.template
中能夠使用vue模版外,其它使用方式相同。
該示例爲原生GridManager的示例,vue版本除了在columnData.text
columnData.template
topFullColumn.template
中能夠使用vue模版外,其它使用方式相同。
ES2015 + webpack + Vue + GridManagerjavascript
npm install gridmanager-vue --save
import GridManagerVue from 'gridmanager-vue'; import 'gridmanager-vue/css/gm-vue.css'; Vue.use(GridManagerVue);
import GridManagerVue from 'gridmanager-vue'; import 'gridmanager-vue/css/gm-vue.css'; new Vue({ el: '#app', components: { GridManagerVue } });
<grid-manager :option="gridOption" :callback="callback" ref="grid"></grid-manager>
const app = new Vue({ el: '#app', data: { // 表格渲染回調函數 // query爲gmOptions中配置的query callback: function(query) { console.log('callback => ', query); }, // 表格 gridOption = { // 表格惟一標識 gridManagerName: 'test-gm', // 高度 height: '300px', // 首次是否加載 firstLoading: false, // 列配置 columnData: [ { key: 'shopId', width: '180px', text: '店鋪id', align: 'center' },{ key: 'platId', text: '平臺', // template=> function: return dom // 參數介紹 // platId: 當前行數據中與配置項key相同字段的值 // row: 當前行數據 // index: 當前行所在數據中的索引值 template: (platId, row, index) => { const span = document.createElement('span'); span.style.color = 'blue'; span.innerText = platId; return span; } },{ key: 'platNick', text: '店鋪名稱', // template=> string dom template: `<span style="color: red">跟據相關法規,該單元格被過濾</span>` },{ key: 'createTime', text: '建立時間', },{ key: 'updateTime', text: '更新時間', // 表頭篩選條件, 該值由用戶操做後會將選中的值以{key: value}的形式覆蓋至query參數內。非必設項 filter: { // 篩選條件列表, 數組對象。格式: [{value: '1', text: 'HTML/CSS'}],在使用filter時該參數爲必設項。 option: [ {value: '1', text: 'HTML/CSS'}, {value: '2', text: 'nodeJS'}, {value: '3', text: 'javaScript'}, {value: '4', text: '前端雞湯'}, {value: '5', text: 'PM Coffee'}, {value: '6', text: '前端框架'}, {value: '7', text: '前端相關'} ], // 篩選選中項,字符串, 默認爲''。 非必設項,選中的過濾條件將會覆蓋query selected: '3', // 否爲多選, 布爾值, 默認爲false。非必設項 isMultiple: false }, // template=> function: return string dom template: updateTime => { return `<span style="color: blue">${updateTime}</span>`; } },{ key: 'action', text: '操做', width: '100px', align: 'center', // template=> function: return vue template // vue模版中將自動添加row字段,該字段爲當前行所使用的數據 // vue模版將不容許再使用template函數中傳入的參數 template:() => { return '<el-button size="mini" type="danger" @click="delRelation(row)">解除綁定</el-button>'; } } ], // 使用分頁 supportAjaxPage: true, // 數據來源,類型: string url || data || function return[promise || string url || data] ajax_data: (settings, params) => { return tenantRelateShop(params); }, // 請求失敗後事件 ajax_error: err => { console.log(err); }, // checkbox選擇事件 checkedAfter: rowList => { this.selectedCheck(rowList); }, // 每頁顯示條數 pageSize: 20 // ...更多配置請參考API } }, methods: { // 解除綁定 delRelation: function(row) { // ... 解除綁定操做 } } });
使用vue-class-component
時,GridManager
中所使用的this指向class,而非Vue.
若是須要將this指向vue, 能夠經過將GridManager
的配置項寫在created內來實現。css
如下方法須要在已經存在gridManager實例的Vue環境下使用。而且使用this.$gridManager
服務須要提早經過Vue.use(GridManagerVue)
將GridManagerVue
註冊至全局組件。
// 推薦使用this.$gridManager方式進行方法調用。 // 刷新 this.$gridManager.refreshGrid('test-gm'); // 或 this.$refs['grid'].$el.GM('refreshGrid', 'test-gm'); // 更新查詢條件 this.$gridManager.setQuery('test-gm', {name: 'baukh'}); // 或 this.$refs['grid'].$el.GM('setQuery', 'test-gm', {name: 'baukh'}); // ...其它更多請直接訪問API
import GridManagerVue from 'gridmanager-vue'; console.log(GridManagerVue.version);