fastadmin 固定列表字段
js整个源码
define(['jquery', 'bootstrap', 'backend', 'table', 'form','bootstrap-table-fixed-columns'], function ($, undefined, Backend, Table, Form) { require.config({ paths: { 'jquery-colorpicker': '../libs/jquery-colorpicker/colorpicker', 'jquery-autocomplete': '../libs/jquery-autocomplete/jquery.autocomplete', 'jquery-tagsinput': '../libs/jquery-tagsinput/jquery.tagsinput', }, shim: { 'jquery-colorpicker': { deps: ['jquery'], exports: '$.fn.extend' }, 'jquery-autocomplete': { deps: ['jquery'], exports: '$.fn.extend' }, 'jquery-tagsinput': { deps: ['jquery', 'jquery-autocomplete', 'css!../libs/jquery-tagsinput/jquery.tagsinput.css'], exports: '$.fn.extend' } } }) var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'facrm/customer/index'+location.search, add_url: 'facrm/customer/add', edit_url: 'facrm/customer/edit', // del_url: 'facrm/customer/del', // multi_url: 'facrm/customer/multi', // import_url: 'facrm/customer/import', // table: 'inquiry_allocation', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', sortOrder: 'desc', searchFormVisible: true, fixedColumns:true, //固定列代码 fixedRightNumber: 1, // // fixedNumber:3, columns: [ [ {checkbox: true}, {field: 'username', title: __('客户名'),operate:'='}, {field: 'label', title: __('客户标签'),operate:'LIKE',formatter:Table.api.formatter.label}, {field: 'company_name', title: __('公司名称'), operate: 'LIKE'}, {field: 'useremail', title: __('客户邮箱'), operate: 'LIKE'}, {field: 'userphone', title: __('客户电话'), operate: 'LIKE',cellStyle:{css:{"max-width":"110px","overflow":"hidden"}}}, {field: 'country', title: __('国家'), operate: 'LIKE'}, {field: 'star_rating', title: __('星级客户'), operate: 'LIKE',formatter:function(value,row,index){ if(row['star_rating']==0){ return "NULL"; }else{ var star = ""; for (i = 0; i < row['star_rating']; i++) { star+="<span class='fa fa-star' style='color:#f5cb0f;font-size:22px'></span>"; } return star; } }}, {field: 'sourcefrom.source_image', title: __('来源'),operate:false,formatter: Table.api.formatter.image}, {field: 'sourcefrom.source_name', title: __('来源方式')}, {field: 'productlist.product_name', title: __('需求产品'), operate: 'LIKE'}, {field: 'ministe.nickname', title: __('业务部长')}, // {field: 'ministe.nickname', title: __('业务')}, {field: 'admin.nickname', title: __('负责人'), formatter:function(value,row,index){ if(row['admin_id']==""){ return '<span class="label" style="background-color:#615da9;">'+自己+'</span>'; }else if(row['admin_id']==1){ return '<span class="label" style="background-color:#615da9;">' + value + '</span>'; }else if(row['admin_id']==2){ return '<span class="label" style="background-color:#fc7293;">' + value + '</span>'; }else if(row['admin_id']==3){ return '<span class="label label-warning">' + value + '</span>'; }else{ return '<span class="label label-info">' + value + '</span>'; } } }, {field: 'status', title: __('Status'), searchList: {"0":__('推进中'),"1":__('已成单'),"2":__('已接单'),"3":__('已放弃')}, formatter: Table.api.formatter.status}, {field: 'high_time', title: __('公海领取'),operate:false,formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD H:m:s"}, {field: 'check_createtime', title: __('分配时间'),operate:false,formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD H:m:s"}, {field: 'datetime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'status', title: __('Status'), searchList: {"0":__('推进中'),"1":__('已成单'),"2":__('已接单'),"3":__('已放弃')}, formatter: Table.api.formatter.status}, {field: 'operate', title: __('Operate'),buttons: [ { name: 'detail', text: __('询盘详情'), title: __('询盘详情'), classname: 'btn btn-xs btn-primary btn-dialog', icon: 'fa fa-list', url: 'inquiry_allocation/detail', }, { name: '跟进', text: __('跟进'), title: __('跟进'), classname: 'btn btn-xs btn-danger btn-dialog', icon: 'fa fa-commenting-o', url: 'facrm/customer/follow_up', refresh:true, }, { name: '公海', text: __('公海'), title: __('公海'), classname: 'btn btn-xs btn-danger btn-ajax', icon: 'fa fa-close', url: 'facrm/customer/high_seas', confirm: '确认把该客户放入公海?', refresh:true, }, ],table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add:function (){ Controller.api.bindevent(); }, edit:function (){ require(['jquery-tagsinput'], function () { //标签输入 var elem = "#c-label"; var tags = $(elem); tags.tagsInput({ width: 'auto', defaultText: '输入后空格确认', minInputWidth: 150, height: '36px', placeholderColor: '#999', onChange: function (row) { if (typeof callback === 'function') { } else { $(elem + "_addTag").focus(); $(elem + "_tag").trigger("blur.autocomplete").focus(); } }, // autocomplete: { // url: 'cms/tag/autocomplete', // minChars: 1, // menuClass: 'autocomplete-tags' // } }); }); Controller.api.bindevent(); }, follow_up:function (){ $("#sub_fllow").on('click',function() { var temp = table.bootstrapTable('getSelections'); var f_content = $("#c-f_content").val(); var next_time = $("#c-next_time").val(); var record_type = $("#c-record_type").find("option:selected").val(); Fast.api.ajax({ type:'POST', url:'facrm/customer/follow_up?ids="+temp"', data:{f_content:f_content,next_time:next_time,record_type:record_type} }, function(data, ret){ //成功的回调 alert(ret.msg); return false; }, function(data, ret){ //失败的回调 alert(ret.msg); return false; }); }) Controller.api.bindevent(); }, follow_up_list:function (){ // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'facrm/customer/follow_up_list', // add_url: 'facrm/customer/add', // edit_url: 'facrm/customer/edit', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'fid', sortName: 'fid', sortOrder: 'desc', columns: [ [ {field: 'kehuname', title: __('客户名称')}, {field: 'f_content', title: __('内容')}, {field: 'nickname', title: __('创建人')}, {field: 'record_type', title: __('跟进方式'),formatter:function (value,row,index){ if(row['record_type']==1){ return "Email"; }else if(row['record_type']==2){ return "whatsapp"; }else{ return "Tel"; } }}, {field: 'next_time', title: __('下次跟进时间')} ] ] }); }, high_seas:function (){ Controller.api.bindevent(); }, unassigned_customers: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'facrm/customer/unassigned_customers', // add_url: 'facrm/customer/add', // edit_url: 'facrm/customer/edit', // del_url: 'facrm/customer/del', // multi_url: 'facrm/customer/multi', // import_url: 'facrm/customer/import', // table: 'inquiry_allocation', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'updatetime', sortOrder: 'desc', columns: [ [ {checkbox: true}, {field: 'sourcefrom.source_image', title: __('来源'),operate:false,formatter: Table.api.formatter.image}, {field: 'sourcefrom.source_name', title: __('来源名称')}, {field: 'username', title: __('客户名'),operate:'='}, {field: 'useremail', title: __('邮箱'), operate: 'LIKE'}, {field: 'userphone', title: __('电话'), operate: 'LIKE',cellStyle:{css:{"max-width":"110px","overflow":"hidden"}}}, {field: 'country', title: __('国家'), operate: 'LIKE'}, {field: 'productlist.product_name', title: __('需求产品'), operate: 'LIKE'}, {field: 'ministe.nickname', title: __('业务部长')}, {field: 'admin.nickname', title: __('询盘负责人'), formatter:function(value,row,index){ if(row['admin_id']==1){ return '<span class="label" style="background-color:#615da9;">' + value + '</span>'; }else if(row['admin_id']==2){ return '<span class="label" style="background-color:#fc7293;">' + value + '</span>'; }else if(row['admin_id']==3){ return '<span class="label label-warning">' + value + '</span>'; }else{ return '<span class="label label-info">' + value + '</span>'; } } }, {field: 'datetime', title: __('Datetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, { field: 'buttons', width: "120px", title: __('分配'), table: table, events: Table.api.events.operate, buttons: [ { name: '✔分配', text: __('✔分配'), title: __('✔分配'), classname: 'btn btn-xs btn-success btn-dialog', url: 'facrm/customer/distribution', refresh:true, }, ],operate:false,formatter: Table.api.formatter.buttons } ] ] }); Controller.api.bindevent(); }, distribution: function () { //分配询盘 $(document).on('click','.distribution',function(event){ Form.api.bindevent($("form[role=form]"),function(data,ret){ if(ret.code==1){ parent.$("#table").bootstrapTable('refresh',{}); }else{ Toastr.success("分配失败"); } }); }) Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });
顶部引入插件的名称:bootstrap-table-fixed-columns