[工具]select2與jqGrid聯(lián)動動態(tài)重新加載數(shù)據(jù)

實(shí)現(xiàn)select2與jqGrid聯(lián)動動態(tài)重新加載數(shù)據(jù)

  1. select2設(shè)置
==== html ====
<select id="sel" class="select2"></select>

==== js ====
var selData = [
     {id: 1, text: 'ER'},
     {id: 2, text: ‘LP'},
     {id: 3, text: ‘LT'},
];
$("#sel").select2({
     data: selData
});

補(bǔ)充:select2的渲染效果實(shí)現(xiàn)必須在html頁面<select>標(biāo)簽加載完成后,js中定義.select2({})激活方法應(yīng)盡量在底部

  1. jqGrid — jqGrid定義在modal框中,每次點(diǎn)擊按鈕打開modal,均根據(jù)select2對應(yīng)ID值,動態(tài)加載user數(shù)據(jù)
 <div class="jqGrid-wrapper"> 
   <table id="grid-table"></table> 
   <div id="grid-pager"></div> 
 </div>
var textModal = $(".getUserModal");    //整個modal的ID
var jqGridTable = $("#grid-table");
var appId = $("#sel option:selected").val(); //獲取select2顯示內(nèi)容對應(yīng)ID
textModal.modal('show');
textModal.on('shown.bs.modal',function () {
    jqGridTable.jqGrid({
    url: 接口URL,
    datatype: "json",
        mtype:'POST',
        styleUI:'Bootstrap',
        colModel: [
            { label: 'id', name: 'id', width: 40, align:"center",hidden:true,title:false},
            { label: 'Name', name: 'name', width: 70,align:"center",title:false}
        ],
        jsonReader:{
            root:"data.contentApproval”,     //獲取返回json參數(shù)中對應(yīng)的user數(shù)據(jù)
            repeatitems : false
       },
        viewrecords: true,
        width: 450,
        height: 230,
        rowNum: 10,
        rownumWidth: 20,
        multiselect: true,
        autowidth:true,
        pager: "#grid-pager"
    });
});
jqGridTab.jqGrid('setGridParam',{
    url: 接口URL(同上),
    datatype : 'json',
    postData:{
    "appId":appId
    },
 }).trigger('reloadGrid');

PS:

JQuery : gt(index)選擇器

$("tr:gt(3)").css("background-color", "yellow");
選取 index +1之后的元素 ,index 值從 0 開始,index=0時表示表格全選

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容