Christian-Yang / Translate-and-save

Translate and save for my self
1 stars 0 forks source link

bootstrap table 学习 #37

Open Christian-Yang opened 7 years ago

Christian-Yang commented 7 years ago

Methods:

bootstrap table 方法Methods
名字:getOptions
参数:无
描述:Return the options object: $table.bootstrapTable('getOptions');
返回bootstrap table 设置中的options选项
名字:getSelections
参数:无
描述:Return all selected rows, when no record selected, am empty array will return: 
返回所有选定的行,当没有选择记录时,空数组将返回
$table.bootstrapTable('getSelections');

名字:getAllSelections
参数:无
描述:Return all selected rows contain search or filter, when no record selected, am empty 
array will return: 
返回所有选定的行包含搜索或过滤器,当没有选择记录时,空数组将返回。
返回所有选择的行,
包括搜索过滤前的,
当没有选择任何行的时候返回一个空数组。

这个与getSelections的区别是:
(1)getAllSelections有搜索框,getAllSelections没有
(2)getAllSelections使用搜索框,搜索了东西,已经看不到勾选的东西了,这个时候,一样能通过
getAllSelections获取到已经选择的东西

$table.bootstrapTable('getAllSelections');
名字:getData
参数:useCurrentPage
描述:Get the loaded data of table: $table.bootstrapTable('getData');
Get the loaded data of table at the moment that this method is called.
 If you set the useCurrentPage to true the method will return the data in the current page.
获取表的加载数据
就是说表中已经加载了那些数据,我可以获取到

获得当前加载的数据。假如设置 
 useCurrentPage 为 true,则返回当前页的数据。
名字:getRowByUniqueId
参数:id
描述:Get data from table, the row that contains the id passed by parameter: 
从表获取数据,包含由参数传递的id的行:
就是说你指定一个id,通过这个唯一的id我们就能从表中获取指定id的数据
根据 uniqueId 获取行数据
$table.bootstrapTable('getRowByUniqueId', 1);
名称:load
参数:data
描述:
Load the data to table, the old rows will be removed: $table.bootstrapTable('load', data);
将数据加载到表中,旧行将被删除
加载数据到表格中,旧数据会被替换
名字:append
参数:data
描述:
Append the data to table: $table.bootstrapTable('append', data);
将数据附加到表
添加数据到表格在,现有数据之后。
名字:prepend
参数:data
描述:插入数据到表格在,现有数据之前
Prepend the data to table: $table.bootstrapTable('prepend', data);
前置数据到表中
名字:remove
参数:params
描述:
从表格中删除数据,包括两个参数:  field: 需要删除的行的 field 名称。
values: 需要删除的行的值,类型为数组。
Remove data from table, the params contains two properties:
field: the field name of remove rows.
values: the array of values for rows which should be removed.
$table.bootstrapTable('remove', {field: 'id', values: ids});
removeAll
Remove all data from table: $table.bootstrapTable('removeAll');
从表中删除所有数据
removeByUniqueId
Remove data from table, the row that contains the id passed by parameter: 
从表中删除数据,该行包含由参数传递的id
(也就是说,可以删除一个指定id的数据行)
$table.bootstrapTable('removeByUniqueId', 1);
insertRow
Insert a new row, the param contains following properties:
插入一个新行,param包含以下属性:
index: the row index to insert into.
index:要插入的行索引。
row: the row data.
行:要插入的行数据。
$table.bootstrapTable('insertRow', {index: 1, row: row});
updateRow
Update the specified row, the param contains following properties: 
更新指定的行,param包含以下属性:
index: the row index to be updated. 
index:要更新的行索引。
row: the row data.
行:要插入的行数据。
$table.bootstrapTable('updateRow', {index: 1, row: row});
updateByUniqueId
Update the specified row, the param contains following properties: 
更新指定的行,param包含以下属性:
id: a row id where the id should be the uniqueid field assigned to the table. 
id:一行id,id应该是分配给表的uniqueid字段。
row: the new row data. $table.bootstrapTable('updateByUniqueId', {id: 3, row: row});
行:新行数据。
showRow/hideRow
Show/Hide the specified row.
显示/隐藏指定的行
$table.bootstrapTable('showRow', {index:1});
$table.bootstrapTable('hideRow', {index:1});
mergeCells
Merge some cells to one cell, the options contains following properties:
将一些单元格合并到一个单元格,该选项包含以下属性:
index: the row index.
index:行索引。
field: the field name.
字段:字段名称。
rowspan: the rowspan count to be merged.
rowspan:要合并的rowspan个数。
colspan: the colspan count to be merged.
colspan:要合并colspan个数。
$table.bootstrapTable('mergeCells', {index: 1, field: 'name', colspan: 2, rowspan: 3});

mergecells

checkAll/uncheckAll
Check/Uncheck all current page rows.
选择/不选择 所有的当前页面的行
$table.bootstrapTable('checkAll');
$table.bootstrapTable('uncheckAll');
check/uncheck
Check/Uncheck a row, the row index start with 0.
选择/不选择 一行,行索引从0开始
$table.bootstrapTable('check', 1);
$table.bootstrapTable('uncheck', 1);
checkBy/uncheckBy
Check/Uncheck rows by array of values.
选择/不选择 行通过指定的数组值
$table.bootstrapTable('checkBy', {field:'id', values:[1, 2, 3]});
$table.bootstrapTable('uncheckBy', {field:'id', values:[1, 2, 3]});

checkby

refresh
Refresh the remote server data, you can set {silent: true} to refresh the data silently, 
and set {url: newUrl} to change the url. To supply query params specific to this request,
 set {query: {foo: 'bar'}}.
$table.bootstrapTable('refresh');

刷新远程服务器数据,您可以设置{silent:true}以静默方式刷新数据,
并设置set{url:newUrl}来更改URL。 要提供特定于此请求的查询参数,
请设置 set{query:{foo:'bar'}}。
$ table.bootstrapTable('刷新');
resetView
重置视图
Reset the bootstrap table view, for example reset the table height:
 $table.bootstrapTable('resetView');
重置表的视图,例如重置表高度:
$ table.bootstrapTable('reset View');
destroy
Destroy the bootstrap table: $table.bootstrapTable('destroy');
销毁bootstrap table
showLoading/hideLoading
显示表数据正在加载中

 $table.bootstrapTable('showLoading');
 $table.bootstrapTable('hideLoading');
showColumn/hideCoulumn
Show/Hide the specified column.
showColumn/ hideCoulumn
显示/隐藏指定的列。
$table.bootstrapTable('showColumn', 'name');
$table.bootstrapTable('hideColumn', 'name');
Scroll to the number value position, set 'bottom' means scroll to the bottom.
滚动到数字值位置,设置“底部”表示滚动到底部。
$table.bootstrapTable('scrollTo', 0);
$table.bootstrapTable('scrollTo', 'bottom');
selectPage/prevPage/nextPage
请选择数据/ prevPage/下一页
Go to the a specified/previous/next page.
转到指定/上一页/下一页。
$table.bootstrapTable('selectPage', 1);
$table.bootstrapTable('prevPage');
$table.bootstrapTable('nextPage');
togglePagination
togglePagination
切换分页选项:$ table.bootstrapTable('togglePagination');
Toggle the pagination option: $table.bootstrapTable('togglePagination');
toggleView
toggleView
切换卡/表视图:$ table.bootstrapTable('toggleView');
Toggle the card/table view: $table.bootstrapTable('toggleView');
refreshOptions

$table.bootstrapTable('refreshOptions', {
                showColumns: true,
                search: true,
                showRefresh: true,
                url: '../json/data1.json'
            });
resetSearch

$button.click(function () {
            $table.bootstrapTable('resetSearch');
        });
expandRow-collapseRow
$button.click(function () {
            $table.bootstrapTable('expandRow', 1);
        });
        $button2.click(function () {
            $table.bootstrapTable('collapseRow', 1);
        });

expandrow-collapserow

filterBy
(Can use only in client-side) Filter data in table, 
e.g. You can filter {age: 10} to show the data only age is equal to 10. 
You can also filter with an array of values, as in: {age: 10, hairColor: ["blue", "red", "green"]} to find data where age is equal to 10 and hairColor is either blue, red, or green.
In this example, we filter by:

$table.bootstrapTable('filterBy', {
    id: [1, 2, 3]
});
过滤
(只能在客户端使用)过滤表中的数据,
例如 您可以过滤{age:10}以显示数据,年龄等于10。
您还可以使用一组值进行过滤,如:{age:10,hairColor:[“blue”,“red”,“green”]}查找年龄等于10的数据,而hairColor为蓝色,红色 ,或绿色。
在这个例子中,我们过滤:

$ table.bootstrapTable('filterBy',{
     id:[1,2,3]
});
Christian-Yang commented 7 years ago

Column options

Column options列参数:
Christian-Yang commented 7 years ago

Table options

Table options表格选项:

通过javascript方式使用bootStrap table,过程如下

```<table id="table"></table>```

[2];在组件的ts文件上写上如下:

$('#table').bootstrapTable({
    columns: [{
        field: 'id',
        title: 'Item ID'
    }, {
        field: 'name',
        title: 'Item Name'
    }, {
        field: 'price',
        title: 'Item Price'
    }],
    data: [{
        id: 1,
        name: 'Item 1',
        price: '$1'
    }, {
        id: 2,
        name: 'Item 2',
        price: '$2'
    }]
});

从上面可以看到,通过使用bootstrapTable这个函数,添加表格选项,比如:columns等等,这个对应于Excel中的Table options表格选项页面。

所有关于表格的设置都在这个页面:http://bootstrap-table.wenzhixin.net.cn/documentation/#table-options

可以使用$.extend()方法来扩张。可以看这个文档:http://www.poluoluo.com/jzxy/201509/424718.html

在使用table option设置表格的时候,可以这样写,写一个tableOption={},然后把设置项,一个一个的添加进去。

例如:

tableOption={
            pagination: true,                   //是否显示分页,设置为 true 会在表格底部显示分页条(*)
            url: '/Export/GetDepartment',         //请求后台的URL(*)
            method: 'get',                      //请求方式(*)
            toolbar: '#toolbar',                //工具按钮用哪个容器,一个jQuery 选择器,指明自定义的toolbar 例如:#toolbar, .toolbar或者是一个Dom节点,比如我们想让一个按钮附加到表格上,让这个按钮和搜索框一行,那么就给这个按钮用一个div包起来,同时给这个div指定一个toolbar的id,或者一个toolbar的类,这样设置到toolbar上,就可以让他们在同一行上了。
            escape:true                       //转义HTML字符串,替换 &, <, >, ", `, 和 ' 字符。过滤危险字符 
            sidePagination: "client",           //分页方式:client客户端分页,server服务端分页(*)
            pageSize: 10,                       //每页的记录行数(*)。如果设置了分页,页面数据条数
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数(*)。就是可以设置一个页面上显示多少条数据,比如一个页面上显示10条,25条,50条,100条。
            search:true,                         //是否启用搜索框
            strictSearch:true,                //设置为 true启用 全匹配搜索,否则为模糊搜索
            searchText:'',                      //初始化搜索文字
            paginationDetailHAlign:

            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)

            sortable: false,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数(*)

            pageNumber: 1,                       //初始化加载第一页,默认第一页

            pageList: [10, 25, 50, 100],        //可供选择的每页的行数(*)
            clickToSelect:true,
            showExport: true,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.
}
Christian-Yang commented 7 years ago

Events 事件

bootstrap table Events 事件
Christian-Yang commented 7 years ago

国际化

可以在bootstrap-table,官方文档http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 页面的最下面找到,关于国际化的所有信息。

bootstrap table 国际化:

We can import all locale files what you need: 你可以导入所有你需要的国际化文件,这些文件都是js文件,它们在node_modules包中的/dist/locale目录下。 所有的国际化的js文件,都在这个链接上可以找到:https://github.com/wenzhixin/bootstrap-table/tree/master/src/locale

<script src="bootstrap-table-en-US.js"></script>
<script src="bootstrap-table-zh-CN.js"></script>

And then use JavaScript to switch locale: 然后使用javascript就可以实现国际化,我们可以把这段代码,添加到组件的构造函数,或者ngOnInit()函数

if(英文) {
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['en-US']);
}
else if (中文){
 $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['zh-CN']);
}
Christian-Yang commented 7 years ago

自定义单元格和事件处理

bootstrap table 自定义单元格显示内容和单元格事件处理

参考资料:http://www.cnblogs.com/yinglunstory/p/6092834.html

bootstrap table官方中的列选项:formatter和events bootstrap table:http://bootstrap-table.wenzhixin.net.cn/documentation/#column-options

bootstrap table可以实现自定义单元格显示内容和这个单元格中的事件处理。例如,想实现如下效果: jquerydemo 那么就需要自定义单元格中的显示内容,因为单元格就是列,所以我们要去bootstrap-table中的列选项中去查看相应的定义和实现。 bootsrtap table的列选项中有一个:formatter。这个选项就可以自定义单元格。 例如:

[1] 在列定义中,以下面的方式定义要自定显示内容的单元格
        {
            field: 'operate',
            title: 'Item Operate',
            align: 'center',
            //定义点击事件,当这个单元格中的内容被点击的时候触发事件
            events: operateEvents,
            //定义单元格中的显示内容 
            formatter: operateFormatter
          }
[2]定义要自定义显示的内容,这个函数需要返回一个字符串。有两种定义方式
   定义方式一: (value, row, index)  => {  return 'string' }
   定义方式二:
     function operateFormatter(value, row, index) {
          return [
            '<a class="like" href="javascript:void(0)" title="Like">',
            '<i class="glyphicon glyphicon-heart"></i>',
            '</a>  ',
            '<a class="remove" href="javascript:void(0)" title="Remove">',
            '<i class="glyphicon glyphicon-remove"></i>',
            '</a>'
          ].join('');
        }
[3]定义上面的自定义的显示内容中点击时候调用的函数。注意上面的两个类,其中一个
```<a class="like">```是``` class="like" ```
另外一个是``` <a class="remove"> ``` 这两个类将来是用来触发事件使用的

    //这里需要在组件的类中定义window:window=window这样的一个window对象。
     window.operateEvents = {
      //当class=".like"被点击时候调用的函数
      'click .like': function (e, value, row, index) {
        alert('You click like action, row: ' + JSON.stringify(row));
      },
      //当class=".remove“被点击时候调用的函数
      'click .remove': function (e, value, row, index) {
        $table.bootstrapTable('remove', {
          field: 'id',
          values: [row.id]
        });
      }
    };
Christian-Yang commented 7 years ago

Column options列参数

bootstrap table 列选项:
Christian-Yang commented 7 years ago

http://blog.csdn.net/april_4/article/details/52846332

Christian-Yang commented 7 years ago

bootstrap table搜索框

bootstrap table搜索框实现

bootstraptable-search

如果想要给一个bootstrap table 添加一个搜索框,那么需要在表格选项中进行设置。 也就是在Table options中有一个选项叫做:search 。这个选项就是用来开启bootstrap table的搜索框的功能。默认这个东西是false的,所以需要在表格中设置为true。

$('.bootstrap-table .search input')这样就能选中这个搜索用的input框,如果要给这个input框设置 placeholder也就是这个搜索框的提示信息,那么只需要这么写$('.bootstrap-table .search input').attr('placeholder','请您搜索!')。这个时候这个搜索框中就会有“请您搜索!”这提示信息,当然这里也可以设置变量。另外如果想让这个input搜索框中能有一个放大镜这样的搜索图标 ,那么需要设置一个span标签通过这个span标签来设置,如下: $('.bootstrap-table .search input').attr('placeholder','请您搜索!').parent().append('<span></span>') 这样这个span标签就和input是同级的,都在<div class="search">这个div下面 然后给这个span设置一个背景图,通过css样式:

.bootstrap-table .search  input + span {
   background:图片地址
}