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

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

如何在JqGrid中顯示間接數(shù)據(jù)

如何在JqGrid中顯示間接數(shù)據(jù)

侃侃爾雅 2019-07-02 14:27:21
如何在JqGrid中顯示間接數(shù)據(jù)我正在我的ASP.NET MVC Web應(yīng)用程序中實(shí)現(xiàn)JqGrid。我有這樣的數(shù)據(jù): SID SNAME CITY  1   ABC   11   2   XYZ   12   3   ACX   13   4   KHG   14   5   ADF   15   6   KKR   16另一張桌子 CID   CNAME  11   Chennai      12   Mumbai   13   Delhi   like this但是,在網(wǎng)格中,我想這樣顯示:  SID SNAME  City   1   ABC   Chennai   2   XYZ   Mumbai   3   ACX   Delhi   4   KHG   Banglore   5   ADF   Hyderabad   6   KKR   Kolkatta我無(wú)法使用JOIN,因?yàn)轭惤Y(jié)構(gòu)如下所示: Class Student{    long sid,    string sname,    long city}所以,當(dāng)我從數(shù)據(jù)庫(kù)中讀取數(shù)據(jù)時(shí),我得到的是城市標(biāo)識(shí),而不是城市名稱。但是,我想在網(wǎng)格數(shù)據(jù)中顯示城市名稱而不是城市ID給最終用戶我需要一些像lookup函數(shù),以便在將數(shù)據(jù)綁定到j(luò)QGrid之前,用城市名稱映射城市id并顯示它,而不是顯示ID。我沒有找到辦法來(lái)完成這件事。請(qǐng)幫忙.。The controller method i am using is as follows:public JsonResult Students()     {         List<Students> liStudents = new  List<Students>();         SortedList<long, string> slLocations = new SortedList<long, string>();         slLocations = Students.LoadLocations();         liStudents = Students.GetStudents();         return Json(liStudents,JsonRequestBehavior.AllowGet);     }如何修改返回語(yǔ)句,以便在json響應(yīng)中也拋出sslLocations
查看完整描述

3 回答

?
ibeautiful

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

我以前已經(jīng)回答過(guò)這個(gè)非公開的問(wèn)題了(見這里)。不過(guò),我決定詳細(xì)回答你的問(wèn)題,因?yàn)槟闼枋龅膯?wèn)題非常普遍。

我首先提醒jqGrid提供formatter: "select"formatoptions.valueeditoptions.value將ID解碼為文本。這個(gè)formatter: "select"使用value和任選separatordelimiterdefaultValue屬性,但它不能使用edoptions.dataUrl從服務(wù)器獲取所需數(shù)據(jù),而不是使用靜態(tài)數(shù)據(jù)value..問(wèn)題很簡(jiǎn)單:處理dataUrl作品異步,但在網(wǎng)格體列的格式化過(guò)程中,不支持延遲填充。所以要用formatter: "select"不得不formatoptions.valueeditoptions.value 以前服務(wù)器響應(yīng)將由jqGrid處理。

在……里面舊的答案我建議將從服務(wù)器返回的JSON響應(yīng)擴(kuò)展為editoptions.value列的formatter: "select"..我建議把beforeProcessing..例如,可以以下格式生成服務(wù)器響應(yīng):

{
    "cityMap": {"11": "Chennai", "12": "Mumbai", "13": "Delhi"},
    "rows": [
        { "SID": "1",  "SNAME": "ABC", "CITY": "11" },
        { "SID": "2",  "SNAME": "XYZ", "CITY": "12" },
        { "SID": "3",  "SNAME": "ACX", "CITY": "13" },
        { "SID": "4",  "SNAME": "KHG", "CITY": "13" },
        { "SID": "5",  "SNAME": "ADF", "CITY": "12" },
        { "SID": "6",  "SNAME": "KKR", "CITY": "11" }
    ]}

并使用以下jqGrid選項(xiàng)

colModel: [
    {name: "SNAME", width: 250},
    {name: "CITY", width: 180, align: "center"}],beforeProcessing: function (response) {
    var $self = $(this);
    $self.jqGrid("setColProp", "CITY", {
        formatter: "select",
        edittype: "select",
        editoptions: {
            value: $.isPlainObject(response.cityMap) ? response.cityMap : []
        }
    });},jsonReader: { id: "SID"}

演示演示了這個(gè)方法。它顯示


可以使用相同的方法動(dòng)態(tài)設(shè)置任何列選項(xiàng)。例如,可以使用

{
    "colModelOptions": {
        "CITY": {
            "formatter": "select",
            "edittype": "select",
            "editoptions": {
                "value": "11:Chennai;13:Delhi;12:Mumbai"
            },
            "stype": "select",
            "searchoptions": {
                "sopt": [ "eq", "ne" ],
                "value": ":Any;11:Chennai;13:Delhi;12:Mumbai"
            }
        }
    },
    "rows": [
        { "SID": "1",  "SNAME": "ABC", "CITY": "11" },
        { "SID": "2",  "SNAME": "XYZ", "CITY": "12" },
        { "SID": "3",  "SNAME": "ACX", "CITY": "13" },
        { "SID": "4",  "SNAME": "KHG", "CITY": "13" },
        { "SID": "5",  "SNAME": "ADF", "CITY": "12" },
        { "SID": "6",  "SNAME": "KKR", "CITY": "11" }
    ]}

和下面的JavaScript代碼

var filterToolbarOptions = {defaultSearch: "cn", stringResult: true, searchOperators: true},
    removeAnyOption = function ($form) {
        var $self = $(this), $selects = $form.find("select.input-elm");
        $selects.each(function () {
            $(this).find("option[value='']").remove();
        });
        return true; // for beforeShowSearch only
    },
    $grid = $("#list");$.extend($.jgrid.search, {
    closeAfterSearch: true,
    closeAfterReset: true,
    overlay: 0,
    recreateForm: true,
    closeOnEscape: true,
    afterChange: removeAnyOption,
    beforeShowSearch: removeAnyOption});$grid.jqGrid({
    colModel: [
        {name: "SNAME", width: 250},
        {name: "CITY", width: 180, align: "center"}
    ],
    beforeProcessing: function (response) {
        var $self = $(this), options = response.colModelOptions, p,
            needRecreateSearchingToolbar = false;
        if (options != null) {
            for (p in options) {
                if (options.hasOwnProperty(p)) {
                    $self.jqGrid("setColProp", p, options[p]);
                    if (this.ftoolbar) { // filter toolbar exist
                        needRecreateSearchingToolbar = true;
                    }
                }
            }
            if (needRecreateSearchingToolbar) {
                $self.jqGrid("destroyFilterToolbar");
                $self.jqGrid("filterToolbar", filterToolbarOptions);
            }
        }
    },
    jsonReader: { id: "SID"}});$grid.jqGrid("navGrid", "#pager", {add: false, edit: false, del: false})
    $grid.jqGrid("filterToolbar", filterToolbarOptions);

演示使用上述代碼。

如果任何選項(xiàng)被動(dòng)態(tài)更改,我們將重新創(chuàng)建搜索篩選器。該方法允許實(shí)現(xiàn)更靈活的解決方案。例如,服務(wù)器可以檢測(cè)客戶端(Web瀏覽器)的語(yǔ)言首選項(xiàng),并根據(jù)這些選項(xiàng)返回?cái)?shù)字、日期等格式選項(xiàng)。我相信每個(gè)人都能提出其他有趣的方案。

再說(shuō)一句。如果您有太多的項(xiàng)目在選擇中(searchoptions.valueeditoptions.value)我建議您不要使用字符串而不是對(duì)象作為searchoptions.valueeditoptions.value..它允許您指定命令元素中的項(xiàng)。

如果您選擇的項(xiàng)目太多(例如,您國(guó)家的所有城市),那么您可以考慮使用選擇2插件,我在其中演示了哪個(gè)用法答案..它簡(jiǎn)化了選項(xiàng)的選擇,因?yàn)樗鼘ELECT in元素轉(zhuǎn)換為非常接近jQueryUI自動(dòng)完成的元素。

下一個(gè)演示演示使用選擇2插件。如果單擊搜索工具欄的“SELECT”元素的下拉箭頭或搜索對(duì)話框,就會(huì)得到額外的輸入字段,可用于快速搜索。如果開始在輸入框中鍵入某些文本(例如,下面圖片中的示例中的“e”),則選項(xiàng)列表將縮減為將類型化文本作為子字符串的選項(xiàng):


我個(gè)人認(rèn)為這樣的“選擇搜索”控制非常實(shí)用。

順便說(shuō)一下我在另一個(gè)答案如何設(shè)置colNames動(dòng)態(tài)的。in可用于管理來(lái)自服務(wù)器端的更多信息。

更新*相應(yīng)的控制器動(dòng)作Students可以是關(guān)于以下內(nèi)容的

public class Student {
   public long SID { get; set; }
   public string SNAME { get; set; }
   public long CITY { get; set; }}public class City {
    public long CID { get; set; }
    public string CNAME { get; set; }}...public class HomeController : Controller {
    ...
    public JsonResult Students () {
        var students = new List<Student> {
                new Student { SID = 1, SNAME = "ABC", CITY = 11 },
                new Student { SID = 2, SNAME = "ABC", CITY = 12 },
                new Student { SID = 3, SNAME = "ABC", CITY = 13 },
                new Student { SID = 4, SNAME = "ABC", CITY = 13 },
                new Student { SID = 5, SNAME = "ABC", CITY = 12 },
                new Student { SID = 6, SNAME = "ABC", CITY = 11 }
            };
        var locations = new List<City> {
                new City { CID = 11, CNAME = "Chennai"},
                new City { CID = 12, CNAME = "Mumbai"},
                new City { CID = 13, CNAME = "Delhi"}
            };
        // sort and concatinate location corresponds to jqGrid editoptions.value format
        var sortedLocations = locations.OrderBy(location => location.CNAME);
        var sbLocations = new StringBuilder();
        foreach (var sortedLocation in sortedLocations) {
            sbLocations.Append(sortedLocation.CID);
            sbLocations.Append(':');
            sbLocations.Append(sortedLocation.CNAME);
            sbLocations.Append(';');
        }
        if (sbLocations.Length > 0)
            sbLocations.Length -= 1; // remove last ';'
        return Json(new {
                   colModelOptions = new {
                       CITY = new {
                           formatter = "select",
                           edittype = "select",
                           editoptions = new {
                               value = sbLocations.ToString()
                           },
                           stype = "select",
                           searchoptions = new {
                               sopt = new[] { "eq", "ne" },
                               value = ":Any;" + sbLocations                           }
                       }
                   },
                   rows = students    
               },
               JsonRequestBehavior.AllowGet);
    }}


查看完整回答
反對(duì) 回復(fù) 2019-07-02
  • 3 回答
  • 0 關(guān)注
  • 666 瀏覽
慕課專欄
更多

添加回答

舉報(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)