bootstrap-table_Ajax加载数据到表格_JSONP(2)

本文介绍了一个使用Bootstrap Table插件实现的固定列表格案例,通过设置fixedColumns和fixedNumber属性,可自定义固定列的数量,提供了良好的用户体验,尤其适用于数据量大且列数较多的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

列头标题JSON:

{
	"columns": [{
		"field": "id",
		"title": "序号",
		"sortable": true
	}, {
		"field": "title",
		"title": "标题",
		"sortable": false
	}, {
		"field": "classid",
		"title": "所属分类",
		"sortable": true
	}, {
		"field": "hits",
		"title": "浏览量",
		"sortable": true
	}, {
		"field": "descriptor",
		"title": "描述",
		"sortable": false
	}]
}

html

<!DOCTYPE html>
<html>
<head>
    <title>Fixed Columns</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-table.css">
    <link rel="stylesheet" href="css/bootstrap-table-fixed-columns.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-table.js"></script>
    <script src="js/bootstrap-table-fixed-columns.js"></script>
</head>
<body>
    <div class="container">
        <h1>Fixed Columns</h1>
        <div class="toolbar form-inline">
            <span>Fixed Number: </span>
            <input class="form-control" id="fixedNumber" type="number" value="1" min="1" max="5">
        </div>
        <table id="table" data-height="400" data-show-columns="true"></table>
    </div>
<script>
    var $table = $('#table');

    $(function () {
        buildTable($table, 20, 20);

        $('#fixedNumber').change(function () {
            buildTable($table, 20, 20);
        });
    });

    function buildTable($el, cells, rows) {
        var i, j, row,
                columns = [],
                data = [];

        $.ajax({
           type: "get",
           async: false,
           url: "data.json",
           dataType: "json",
           success: function(json){
                columns = json.columns;
                // data = json.data;
           }
        })

        $.ajax({
           type: "get",
           async: false,
           url: "http://e945.net/index.php?c=api&a=data&jsoncallback=?",
           dataType: "jsonp",
           jsonp: "jsoncallback",
           // jsonpCallback: "", //回调
           success: function(jsonp){
                $el.bootstrapTable('destroy').bootstrapTable({
                    columns: columns,
                    data: jsonp,
                    search: true,
                    toolbar: '.toolbar',
                    fixedColumns: true,
                    fixedNumber: +$('#fixedNumber').val()
                });
           }
        })

        
    }
</script>
</body>
</html>```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值