bootstrap table x-editable select2——带图标的选择
2017-10-01 22:27
274 查看
select2支持带图标的选择项,用Templating。
那么在bootstrap table中的x-editable怎样用呢?先看动画和图片:
首先我们制作这些图标:
用excel做饼图——饼图拷入powerpoint——然后用powerpoint制作成透明图制作透明图
做好的图标:
看看前端代码吧:
参考了:x-editable的http://jsfiddle.net/wQysh/8/
bootstrap table的例子:#2314 Use
editable and formatter: https://jsfiddle.net/fsauter/5shvjxej/
select2的例子:https://select2.org/data-sources/ajax
<table id="table" data-query-params="queryParams" data-url="/getprogress" data-toolbar="#toolbar" data-search="true" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-striped="true" data-clickToSelect="true" data-show-export="true" data-filter-control="true" > <thead> <tr> <th>选择</th> <th data-field="id" data-width="10" data-align="center" data-valign="middle">序号</th> <!-- <th data-field="name" data-editable="true" data-editable-emptytext="For free." data-editable-display-formatter="nameFormatter">Price</th> --> <th data-field="name1" data-editable="true" data-editable-emptytext="For free." data-editable-display-formatter="priceFormatter" data-align="center" data-align="center" data-valign="middle" data-title-tooltip="content">设计</th> <th data-field="path1" data-editable="true" data-editable-emptytext="For free." data-editable-display-formatter="priceFormatter1" data-width="100" data-align="center" data-valign="middle">流程</th> <th data-field="name2" data-editable="true" data-editable-emptytext="For free." data-editable-display-formatter="priceFormatter" data-width="10" data-align="center" data-valign="middle">校核</th> <th data-field="path2" data-editable="true" data-editable-emptytext="For free." data-editable-display-formatter="priceFormatter1" data-width="100" data-align="center" data-valign="middle">流程</th> <th data-field="name3" data-editable="true" data-editable-emptytext="For free." data-editable-display-formatter="priceFormatter" data-width="10" data-align="center" data-valign="middle">审查</th> </tr> </thead> </table>
$(function (value, sourceData) { $('#table').bootstrapTable({ idField: 'id', uniqueId:'id', // url: '/getprogress',///achievement/send/1 // striped: "true", columns: [ { checkbox:true, width:10 }, { // field: 'Number', title: '序号', formatter:function(value,row,index){ return index+1 } },{ visible: true, width:10, editable: { params:function(params) { //originally params contain pk, name and value var selectRow3=$('#table').bootstrapTable('getSelections'); var ids=""; for(var i=0;i<selectRow3.length;i++){ if(i==0){ ids=selectRow3[i].id; }else{ ids=ids+","+selectRow3[i].id; } } params.ids = ids; return params; }, type: 'select2', select2: { allowClear: true, width: '150px', placeholder: '请选择', // multiple: true placeholder: 'Select Task Progress', // minimumInputLength: 0, id: function (item) { return item.Id; }, ajax: { url: '/getselect',//这里要修改一下 dataType: 'json', data: function (term, page) { return { query: term }; }, results: function (data, page) { // alert(JSON.stringify(data)); return { results: data }; } }, formatResult: function (item) { // return item.Nickname; // alert(item.name); var baseUrl = "/static/img"; var $state = $('<span><img src="' + baseUrl + '/' + item.name1 + '.png" class="img-flag" width="20%"/> ' + item.content + '</span>'); return $state; }, formatSelection: function (item) { // alert(item.name); // return item.name; var baseUrl = "/static/img"; var $state = $('<span><img src="' + baseUrl + '/' + item.name1 + '.png" class="img-flag" width="20%"/> ' + item.content + '</span>'); return $state; }, initSelection: function (element, callback) {//这个是默认值 // alert(JSON.stringify(element)); // alert(element.val()); // return {"Id":1,"name":"0","content":"未启动"} return $.get('/getprogress1', { query: element.val()}, function (data) { // alert(JSON.stringify(data)); callback(data); }); } },//'/regist/getuname1',//这里用get方法,所以要换一个 pk: 1, url: '/modifyprogress', title: 'Enter Progress', success: function(response, newValue) { // alert(response.name);//这个是反馈回来的值 // alert(newValue);//这个是选择的顺序值 var selectRow3=$('#table').bootstrapTable('getSelections'); for(var i=0;i<selectRow3.length;i++){ alert(selectRow3[i].Id); $('#table').bootstrapTable('updateByUniqueId', { id: selectRow3[i].Id, row: { name1: response.name1 } }); } } } } ], }); }); var scope = this; scope.nameFormatter = function(value) { var icon = $(this).data('pk') % 2 === 0 ? 'glyphicon-star' : 'glyphicon-star-empty'; var markup = '<i class="glyphicon ' + icon + '"></i> ' + value; $(this).html(markup); }; scope.priceFormatter = function(value) { // alert(value); if (value=="0"){ title="未开始" }else if(value=="0.125"){ title="完成1/8" }else if(value=="0.25"){ title="完成1/4" }else if(value=="0.375"){ title="完成3/8" }else if(value=="0.5"){ title="完成1/2" }else if(value=="0.625"){ title="完成5/8" }else if(value=="0.75"){ title="完成3/4" }else if(value=="0.875"){ title="完成7/8" }else if(value=="1"){ title="任务完成" }; var color = '#' + Math.floor(Math.random() * 6777215).toString(16); var markup = '<div title="' + title + '" style="color: ' + color + '">' + '<span><img src="/static/img/' + value + '.png" class="img-flag" width="80%"/> </span></div>'; $(this).html(markup); }; scope.priceFormatter1 = function(value) { if (value=="dashed"){ title="未开始" }else if(value=="solid"){ title="已开始" } var color = '#' + Math.floor(Math.random() * 6777215).toString(16); var markup = '<div title="' + title + '" style="color: ' + color + '">' + '<span><img src="/static/img/' + value + 'arrow-redd.png" class="img-flag" width="100%"/> </span></div>'; $(this).html(markup); }; // $.fn.editable.defaults.mode = 'inline'; $.fn.editable.defaults.display = function(value, sourceData) { var displayFormatterFunction = $(this).data('display-formatter'); if (displayFormatterFunction) { scope[displayFormatterFunction].call(this, value, sourceData); } else { $(this).html(value); } };
相关文章推荐
- bootstrap-table 中columns中editable type为select默认使用本列数据
- bootstrapTable editable select empty
- 如何通combobox中的select标签选择不同的值展示不同的echarts图标
- 【BootStrap】关于Select下拉框选择触发事件以及扩展
- BootStrap中关于Select下拉框选择触发事件及扩展
- Bootstrap 表单控件一(单行输入框input,下拉选择框select ,文本域textarea)
- 批次查找策略select * from 存取顺序找到的批次表table where 选择条件B sort by 排序C
- bootstrap multiselect插件级联选择框操作 内容从json文件获取
- 第20篇:基于bootstrap-datatimepicker带时间段的选择 (与multiselect搭配使用,与angular搭配使用)
- bootstrap-table 选择行,并且获得选中行的所有数据内容
- select选择框控件-jquery.editable-select
- Boostrap-table.js的表格数据可视化 集成bootstrap-editable.js
- 很不错的两款Bootstrap Icon图标选择组件
- JS组件系列——不容错过的两款Bootstrap Icon图标选择组件
- asp select下拉菜单选择图标并实时显示
- Laravel与bootstrap-editable实现table的行内编辑
- JS表格组件BootstrapTable行内编辑解决方案x-editable
- Bootstrap系列 -- 15. 下拉选择框select【转发】
- bootstrap--table,select2及x-editable的使用小结
- JS组件系列之Bootstrap Icon图标选择组件