amber

amber

FastAdmin 個人記錄 - 自定義搜索渲染

單個字段自定義搜索渲染#

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 判斷

具體鏈接

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。