第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

jqGrid動(dòng)態(tài)列綁定

jqGrid動(dòng)態(tài)列綁定

月關(guān)寶盒 2019-10-11 10:09:19
如何動(dòng)態(tài)綁定jqGrid?這些列在設(shè)計(jì)時(shí)不可用,而僅在運(yùn)行時(shí)可用。在當(dāng)前的jqGrid設(shè)計(jì)中,必須預(yù)先填充colmodels和其他屬性,以使網(wǎng)格正常工作。對(duì)此方向的任何輸入將不勝感激。
查看完整描述

3 回答

?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

我的解決方案與Teoman Shipahi自2015年8月以來的出色回答相同。


我有一個(gè)Web服務(wù),該服務(wù)返回一組JSON數(shù)據(jù),但是實(shí)際的列可能會(huì)隨時(shí)間變化。


我想做的是在jqGrid中隱藏一些JSON列,并根據(jù)此特定JSON字段是否為重要字段之一(在本例中為SegmentName)來設(shè)置某些列的寬度。


這是我想出的:


$(function () {

    //  Load the JSON data we'll need to populate our jqGrid


    // ID of a [Segment_Set] record in our database (which our web service will load the data for.

    var SegmentSetId = 12345;


    $.ajax(

    {

        type: "GET",

        url: "/Service1.svc/LoadSegmentAttributes/" + SegmentSetId,

        dataType: "json",

        success: function (JSONdata) {

            // 

            //  Work through our JSON data, and create the two arrays needed by jqGrid 

            //  to display this dynamic data.

            //

            var listOfColumnModels = [];

            var listOfColumnNames = [];


            for (var prop in JSONdata[0]) {

                if (JSONdata[0].hasOwnProperty(prop)) {

                    //  We have found one property (field) in our JSON data.

                    //  Add a column to the list of Columns which we want our jqGrid to display

                    listOfColumnNames.push(prop);


                    //  How do we want this field to be displayed in our jqGrid ?

                    var bHidden = (prop == "SegmentID") || (prop == "SegmentSequenceInx");

                    var columnWidth = (prop == "SegmentName") ? 200 : 50;


                    listOfColumnModels.push({

                        name: prop,

                        width: columnWidth,

                        sortable: true,

                        hidden: bHidden

                    });

                }

            }


            //  Now we have our JSON data, and list of Column Headings and Models, we can create our jqGrid.

            CreateJQGrid(JSONdata, listOfColumnModels, listOfColumnNames);

        }

    });

});

這是創(chuàng)建jqGrid的函數(shù):


function CreateJQGrid(JSONdata, listOfColumnModels, listOfColumnNames) {

    //  After loading the JSON data from our webservice, and establishing the list of 

    //  Column Names & Models, we can call this function to create the jqGrid.

    $("#SegmentRulesGrid").jqGrid({


        datatype: "local",

        data: JSONdata,

        localReader: {

            id: "SegmentID",        //  The Primary Key field in our JSONdata 

            repeatitems: false

        },

        mtype: "GET",

        colNames: listOfColumnNames,

        colModel: listOfColumnModels,

        rowNum: 15,

        loadonce: true,

        gridview: true,

        autowidth: true,

        height: 350,

        pager: '#pager',

        rowList: [15, 30, 100, 300],

        rownumbers: true,

        viewrecords: true,

        caption: 'Segment Rules',

    });

}

希望這可以幫助。


顯然,我的解決方案的一個(gè)缺點(diǎn)是,它堅(jiān)持要求您在將所有 JSON數(shù)據(jù)顯示在網(wǎng)格中之前先加載所有 JSON數(shù)據(jù),而不是一次僅加載一頁數(shù)據(jù)。如果您有大量數(shù)據(jù),這可能是個(gè)問題。


查看完整回答
反對(duì) 回復(fù) 2019-10-11
?
慕的地10843

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊

另一個(gè)解決方案;


 $("#datagrid").jqGrid({

        //url: "user.json",

        //datatype: "json",

        datatype: "local",

        data: dataArray,

        colNames:getColNames(dataArray[0]),

        colModel:getColModels(dataArray[0]),

        rowNum:100,

        loadonce: true,

        pager: '#navGrid',

        sortname: 'SongId',

        sortorder: "asc",

        height: "auto", //210,

        width:"auto",

        viewrecords: true,

        caption:"JQ GRID"

    });


    function getColNames(data) {

        var keys = [];

        for(var key in data) {

            if (data.hasOwnProperty(key)) {

                keys.push(key);

            }

        }


        return keys;

    }


    function  getColModels(data) {

        var colNames= getColNames(data);

        var colModelsArray = [];

        for (var i = 0; i < colNames.length; i++) {

            var str;

            if (i === 0) {

                str = {

                    name: colNames[i],

                    index:colNames[i],

                    key:true,

                    editable:true

                };

            } else {

                str = {

                    name: colNames[i],

                    index:colNames[i],

                    editable:true

                };

            }

            colModelsArray.push(str);

        }


        return colModelsArray;

    }

查看完整回答
反對(duì) 回復(fù) 2019-10-11
  • 3 回答
  • 0 關(guān)注
  • 815 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)