bootstrap table添加行

1.bootstrap table添加行

<!DOCTYPE html>
<html>
  <head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<link href="bootstrap-table.min.css" rel="stylesheet" />  
<script src="bootstrap-table.js"></script>  
<script src="bootstrap-table-locale-all.min.js"></script>  
</head>
<body>
<div class="col-md-12">  
<button type="button" class="btn btn-default" id="addData" οnclick="xx()">  ttttt
                <span class="glyphicon glyphicon-plus"></span>  
            </button>  
    <table class="table table-striped table-bordered table-hover" id="subprocessTable"></table>  
</div>  
<script>
    /** 
     * add a new row 
     */  
   function xx(){    alert();
        $('#subprocessTable').bootstrapTable('selectPage', 1); //Jump to the first page  
        var data = {'ii': '', 'aa': ''}; //define a new row data,certainly it's empty  

        $('#subprocessTable').bootstrapTable('prepend', data); //the method of prepend must defined all fields,but append needn't  
        //$('#dataTable').bootstrapTable('append',data);  
  
        $("#dataTable tr:eq(1) td:eq(0)").trigger("dblclick");  
        $("#dataTable input")[0].focus();  
 }

$(function(){  
    //初始化表格  
    $('#subprocessTable').bootstrapTable({  
       data:[{'ii':'aa','aa':'bb'},{'ii':'a55a','aa':'b55b'}],  
        editable:true,//开启编辑模式  
        clickToSelect: true,  
        cache: false,  
        showToggle:true, //显示切换按钮来切换表/卡片视图。  
        showPaginationSwitch:true, //显示分页切换按钮  
        pagination: true,  
        pageList: [10,25,50,100],  
        pageSize:10,  
        pageNumber:1,  
        uniqueId: 'index', //将index列设为唯一索引  
        striped: true,  
        search: true,  
        showRefresh: true,  
        minimumCountColumns: 2,  
        smartDisplay:true,  
        columns: [  
            [  
                {field:"ii",title:"ID",align:"center",edit:true,formatter:function(value, row, index){  
                    return row.index=index ; //返回行号  
                }},
                {field:"aa",title:"Description",edit:true,align:"center"}
               
            ]  
        ]  
    });  
  

});  
</script>  
</body>
</html>

以下是使用Bootstrap Table删除的方法和示例代码: 1. 在HTML文件中引入Bootstrap Table的CSS和JS文件: ```html <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.css"> <script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.js"></script> ``` 2. 在HTML文件中创建一个表格,并设置表格的ID和data-url属性: ```html <table id="table" data-url="data.json"></table> ``` 3. 在JavaScript文件中初始化表格,并添加删除按钮的点击事件: ```javascript $(function () { // 初始化表格 $('#table').bootstrapTable({ columns: [{ field: 'id', title: 'ID' }, { field: 'name', title: 'Name' }, { field: 'price', title: 'Price' }], data: [{ id: 1, name: 'Item 1', price: '$1' }, { id: 2, name: 'Item 2', price: '$2' }, { id: 3, name: 'Item 3', price: '$3' }] }); // 添加删除按钮的点击事件 $('#delete').click(function () { var ids = $.map($('#table').bootstrapTable('getSelections'), function (row) { return row.id; }); $('#table').bootstrapTable('remove', { field: 'id', values: ids }); }); }); ``` 在上面的代码中,我们首先使用`bootstrapTable()`方法初始化了一个表格,并设置了表格的列和数据。然后,我们添加了一个删除按钮的点击事件,该事件会获取选中的ID,并使用`remove()`方法从表格中删除这些
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值