bootstrap-table formatter 使用vue組件的方法
bootstrap-table簡(jiǎn)介
•1.1、bootstrap table簡(jiǎn)介及特征:
Bootstrap table是國(guó)人開(kāi)發(fā)的一款基于 Bootstrap 的 jQuery 表格插件,通過(guò)簡(jiǎn)單的設(shè)置,就可以擁有強(qiáng)大的單選、多選、排序、分頁(yè),以及編輯、導(dǎo)出、過(guò)濾(擴(kuò)展)等等的功能。目前在github上已經(jīng)有2600多個(gè)Star,可見(jiàn)其受歡迎程度。其官方網(wǎng)站地址 為:http://bootstrap-table.wenzhixin.net.cn/。里面可以下載使用所需的JS和CSS文件,以及參考文檔和例子。
•支持 Bootstrap 3 和 Bootstrap 2
•自適應(yīng)界面
•固定表頭
•非常豐富的配置參數(shù)
•直接通過(guò)標(biāo)簽使用
•顯示/隱藏列
•顯示/隱藏表頭
•通過(guò) AJAX 獲取 JSON 格式的數(shù)據(jù)
•支持排序
•格式化表格
•支持單選或者多選
•強(qiáng)大的分頁(yè)功能
•支持卡片視圖
•支持多語(yǔ)言
•支持插件
下面通過(guò)實(shí)例代碼給大家介紹bootstrap-table formatter 使用vue組件的方法,具體代碼如下所示:
import { Subject } from "rxjs";
import Vue from "vue";
export const BtEventHub = new Subject();
const VueComList = [];
let VueComId = 0;
BtEventHub.debounceTime(10)
.filter(() => VueComList.length > 0)
.delay(10)
.subscribe(function() {
const len = VueComList.length - 1;
for (let i = len; i >= 0; i--) {
const item = VueComList[i];
const dom = document.getElementById(item.name);
if (dom != null) {
new Vue(item);
VueComList.splice(i, 1);
}
}
if (VueComList.length === 0) {
VueComId = 0;
}
});
export function BtAddVueCom(obj: object) {
const id = `_vue_com_${VueComId++}`;
VueComList.push({
el: "#" + id,
name: id,
...obj
});
setTimeout(() => {
BtEventHub.next();
}, 0);
return id;
}
window["BtAddVueCom"] = BtAddVueCom;
function ColFormatter1(value, row) {
const id = window.BtAddVueCom({
template: '<el-switch v-model="row.IsShow"></el-switch>',
data: function () {
return {
row
}
}
});
return `<div id="${id}"></div>`;
}
ps:Vue 結(jié)合bootstrap table插件使用
bootstrap Table插件可以很方便的搜索排序,方便快捷,下面是結(jié)合vue的完整的例子。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue Bootstrap Table Demo</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css" rel="external nofollow" >
<link rel="stylesheet" href="../plugins/bootstrap-table-develop/src/bootstrap-table.css" rel="external nofollow" >
</head>
<body class="">
<div>
<table class="table table-bordered table-striped" id="tableTest1">
</table>
</div>
<script src="../jQuery/jQuery-2.1.4.min.js"></script>
<script src="../dist/vue.js"></script>
<script src="../plugins/bootstrap-table-develop/src/bootstrap-table.js"></script>
<script src="../plugins/bootstrap-table-develop/src/locale/bootstrap-table-zh-CN.js"></script>
<script>
var app7 = new Vue({
el: '#tableTest1',
data: {
//message: [],
message: [],
columns: [{
title: 'Id',
field: 'id'
},
{
field: 'name',
title: 'Item Name'
}, {
field: 'url',
title: 'url'
}, {
field: 'alex',
title: 'alex'
}, {
field: 'country',
title: 'country'
}
],
},
created() {
//console.log(this.message)
this.getData();
this.intervalGetData();
//console.log(this.message)
},
methods: {
intervalGetData() {
setInterval(() => {
// $.get("selectBtTable.php?action=init_data_list", data => {
// var data = JSON.parse(data);
// this.message = data;
// $('#tableTest1').bootstrapTable('load', this.message);
// //console.log(JSON.parse(data))
// console.log("get data")
// })
this.getData();
}, 3000)
},
getData() {
//es6 箭頭函數(shù)的寫(xiě)法
// $.get("selectBtTable.php?action=init_data_list", data => {
// var data = JSON.parse(data);
// this.message = data;
// $('#tableTest1').bootstrapTable('load', this.message);
// console.log("init data")
// })
var that = this;
$.get("selectBtTable.php?action=init_data_list", function(data) {
var data = JSON.parse(data);
that.message = data;
$('#tableTest1').bootstrapTable('load', that.message);
console.log("init data")
})
}
},
mounted() {
console.log(this.message + "mounted")
$('#tableTest1').bootstrapTable({ columns: this.columns, height: 500, search: true });
}
})
</script>
</body>
</html>
(adsbygoogle = window.adsbygoogle || []).push({});
總結(jié)
以上所述是小編給大家介紹的bootstrap-table formatter 使用vue組件的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
JavaScript開(kāi)發(fā)人員的10個(gè)關(guān)鍵習(xí)慣小結(jié)
還在一味沒(méi)有目的的編寫(xiě)JavaScript代碼嗎?那么你就OUT了!讓我們一起來(lái)看看小編為大家搜羅的JavaScript開(kāi)發(fā)人員應(yīng)該具備的十大關(guān)鍵習(xí)慣吧2014-12-12
解決使用layui的時(shí)候form表單中的select等不能渲染的問(wèn)題
今天小編就為大家分享一篇解決使用layui的時(shí)候form表單中的select等不能渲染的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09
js實(shí)現(xiàn)無(wú)限瀑布流實(shí)例方法
在本篇文章里小編給大家整理的是關(guān)于js實(shí)現(xiàn)無(wú)限瀑布流實(shí)例方法以及相關(guān)代碼,需要的朋友們學(xué)習(xí)下吧。2019-09-09
前端實(shí)現(xiàn)監(jiān)控SDK的實(shí)戰(zhàn)指南
本文討論了前端監(jiān)控和數(shù)據(jù)統(tǒng)計(jì)的設(shè)計(jì)思路,包括錯(cuò)誤監(jiān)控、用戶行為日志、PV/UV統(tǒng)計(jì)等方面,介紹了數(shù)據(jù)采集、日志上報(bào)、日志查詢的流程,以及監(jiān)控錯(cuò)誤的類型和用戶埋點(diǎn)統(tǒng)計(jì)的手段,同時(shí)提到了PV和UV的統(tǒng)計(jì)方法,需要的朋友可以參考下2024-10-10
QQ強(qiáng)制聊天功能代碼(加強(qiáng)版,兼容QQ2010)
QQ強(qiáng)制聊天功能代碼,腳本之家以前也發(fā)布過(guò),但已經(jīng)不能用了,這個(gè)是新版本,經(jīng)過(guò)測(cè)試,完全兼容新版本的qq.2010-06-06
js隨機(jī)顏色代碼的多種實(shí)現(xiàn)方式
本篇文章小編為大家介紹,js隨機(jī)顏色代碼的多種實(shí)現(xiàn)方式。需要的朋友參考下2013-04-04
TypeScript中枚舉類型的理解與應(yīng)用場(chǎng)景
如 TypeScript 官方文檔所說(shuō),枚舉類型是對(duì) JavaScript 標(biāo)準(zhǔn)數(shù)據(jù)類型集的擴(kuò)充,所以下面這篇文章主要給大家介紹了關(guān)于TypeScript中枚舉類型的理解與應(yīng)用場(chǎng)景的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09

