1. 程式人生 > >bootstrap-table 的回掉函式 ! 不用寫在bootstrap初始化裡的!

bootstrap-table 的回掉函式 ! 不用寫在bootstrap初始化裡的!

$(function(){
            /*初始化表格*/
            $("#goods").bootstrapTable({
                data: data
            });
            /*載入事件*/
            $("#goods")
            .on('click-row.bs.table', function (e, row, ele,field) {
                $("#eventInfo").text('點選行事件 當前商品名:'+ row.goodsName
                                    + ',價格:' + row.price
                                    + ',效期:' + row.date
                                    + '當前點選單元格field值為:' + field);
            })
            .on('dbl-click-row.bs.table', function (e, row, ele,field) {
                $("#eventInfo").text('雙擊行事件');
            })
            .on('check.bs.table', function (e, row,ele) {
                $("#eventInfo").text('checkbox選中事件');
            })
            .on('uncheck.bs.table', function (e, row,ele) {
                $("#eventInfo").text('checkbox取消選中事件');
            })
            .on('sort.bs.table', function (e, field, order) {
                var o;
                switch(order){
                    case "desc":
                    o = "降序";
                    break;
                    case "asc":
                    o = "升序";
                    break;
                }
                $("#eventInfo").text('排序事件 當前' + name + '列,以' + o + "排列");
            })
            .on('check-all.bs.table', function (e,dataArr) {
                $("#eventInfo").text('全選事件');
            })
            .on('uncheck-all.bs.table', function (e,dataArr) {
                $("#eventInfo").text('取消全選事件');
            })
            .on('load-success.bs.table', function (e, data) {
                $("#eventInfo").text('載入成功事件');
            })
            .on('load-error.bs.table', function (e, status) {
                $("#eventInfo").text('載入錯誤事件');
            })
            .on('column-switch.bs.table', function (e, field, checked) {
                var colName;
                switch(field){
                    case "goodsName":
                    colName = "商品名稱";
                    break;
                    case "price":
                    colName = "價格";
                    break;
                    case "date":
                    colName = "日期";
                    break;
                }
                if(checked){
                    $("#eventInfo").text('篩選列事件 ' + colName + '列顯示');
                }else{
                    $("#eventInfo").text('篩選列事件 ' + colName + '列隱藏');
                }
            })
            .on('page-change.bs.table', function (e, number, size) {
                $("#eventInfo").text('切換頁事件 當前頁數:第' + number + "頁,每頁顯示數量" + size + "條");
            })
            .on('search.bs.table', function (e, text) {
                $("#eventInfo").text('搜尋事件');
            });
        });