# 单个字段自定义搜索渲染
selectpage 搜索 例:customerID 按需替换
// 在普通搜索渲染后 | |
table.on('post-common-search.bs.table', function (event, table) { | |
var form = $("form", table.$commonsearch); | |
$("input[name='customerID']", form).addClass("selectpage").data("source", "customer/customer/index").data("primaryKey", "id").data("field", "charname").data("orderBy", "id desc"); | |
Form.events.cxselect(form); | |
Form.events.selectpage(form); | |
}); |
等于排除 搜索 例:mid 按需替换
// 在普通搜索渲染后 | |
table.on('post-common-search.bs.table', function (event, table) { | |
var form = $("form", table.$commonsearch); | |
let html = '<!--显式的operate操作符-->\n' + | |
' <div class="input-group">\n' + | |
' <div class="input-group-btn">\n' + | |
' <select class="form-control operate" data-name="mid" style="width:60px;">\n' + | |
' <option value="=" selected>等于</option>\n' + | |
' <option value="<>">排除</option>\n' + | |
' </select>\n' + | |
' </div>\n' + | |
' <input class="form-control" type="text" name="mid" id="mid" placeholder="" value=""/>\n' + | |
' </div>' | |
$("input[name='mid']", form).parent().html(html); | |
}); |
# 开发示例 自定义搜索表单模板 searchFormTemplate
searchFormTemplate
table.bootstrapTable({ | |
...省略 | |
searchFormVisible: true, | |
searchFormTemplate: 'customformtpl', | |
...省略 | |
}) |
对应模板
<script id="customformtpl" type="text/html"> | |
<!--form表单必须添加form-commsearch这个类--> | |
<form action="" class="form-commonsearch"> | |
<div style="border-radius:2px;margin-bottom:10px;background:#f5f5f5;padding:15px 20px;"> | |
<h4>自定义搜索表单</h4> | |
<hr> | |
<div class="row"> | |
<div class="col-xs-12 col-sm-6 col-md-3"> | |
<div class="form-group"> | |
<label class="control-label">ID</label> | |
<!--显式的operate操作符--> | |
<div class="input-group"> | |
<div class="input-group-btn"> | |
<select class="form-control operate" data-name="id" style="width:60px;"> | |
<option value="=" selected>等于</option> | |
<option value=">">大于</option> | |
<option value="<">小于</option> | |
</select> | |
</div> | |
<input class="form-control" type="text" name="id" placeholder="" value=""/> | |
</div> | |
</div> | |
</div> | |
<div class="col-xs-12 col-sm-6 col-md-3"> | |
<div class="form-group"> | |
<label class="control-label">标题</label> | |
<!--隐式的operate操作符,必须携带一个class为operate隐藏的文本框,且它的data-name="字段",值为操作符--> | |
<input class="operate" type="hidden" data-name="title" value="="/> | |
<div> | |
<input class="form-control" type="text" name="title" placeholder="请输入查找的标题" value=""/> | |
</div> | |
</div> | |
</div> | |
<div class="col-xs-12 col-sm-6 col-md-3"> | |
<div class="form-group"> | |
<label class="control-label"></label> | |
<div class="row"> | |
<div class="col-xs-6"> | |
<input type="submit" class="btn btn-success btn-block" value="提交"/> | |
</div> | |
<div class="col-xs-6"> | |
<input type="reset" class="btn btn-primary btn-block" value="重置"/> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</form> | |
</script> |
# 表格自定义搜索拓展,下拉搜索操作符
- 给表格 field,增加 operate: 'number' ,自定义搜索等于大于小于
- 在 public/assets/js/bootstrap-table-commonsearch.js 新增 number 判断
具体链接
- https://ask.fastadmin.net/article/10753.html