2015-06-04 30 views
0

在我的jqGrid實現中,我們有一個下拉式的子網格,我們希望在更改下拉菜單時更改單元格中的圖標。我使用了Formatter來生成下圖所示的圖標。但現在我想添加/刪除單元格中的圖標圖像。這可能嗎?我非常感謝任何幫助/想法?我們在這個項目中使用了jqGrid for ASP .NET。如何更改jqGrid中特定單元格的Html?

enter image description here

function formatActionGridIcons(cellValue, options, rowObject) { 
    if (cellValue.indexOf("_") == -1) return ''; 

    var arr = cellValue.split('_'); 

    var icon1 = arr[0]; 
    var icon2 = arr[1]; 
    var icon3 = arr[2]; 

    //if (icon1 == "R") 
    var cellHtml = getIconHtml(icon1) + getIconHtml(icon2) + getIconHtml(icon3); 
    return cellHtml; 

} 
function getIconHtml(icon) { 
    if (icon == null || icon == "") return ""; 
    var result = GetIconPath(icon); 
    if (typeof (result) === "undefined" || result == "") 
     return ""; 
    else 
     return "<img src='" + GetIconPath(icon) + "' width='18px' height='18px' />"; 
} 
function unformatActionGridIcons(cellValue, options, cellObject) { 
    return $(cellObject.html()).attr("originalValue"); 
} 
+0

您可以使用_custom formatter_。如果你可以發佈這個格式化器的colmodel,那最好發表一些想法。 – Jai

+0

感謝Jai,這是使用自定義格式化程序完成的。我可以在源代碼中看到colModel。請記住,這是用於ASP .NET的jqGrid的商業版本,因此我們將這些列定義爲ASP .NET控件標記。但是我已經在這裏發佈了自定義格式化程序的代碼。 –

+0

'getIconHtml'的代碼看起來很奇怪,因爲它返回* always *空字符串'「」'(同時參見if和else)。 – Oleg

回答

1

您可以使用setCell與圖標,以修改單元格。它在內部調用單元的格式化程序以生成將在網格中設置的HTML片段。因此,您需要爲其3-d參數使用相同格式的數據setCell,就像您在網格輸入中使用的那樣。

+0

是的,工作。謝謝。一個側面的問題,但。是否有可能從具有自定義格式化器的列中提取原始值?我在'UnFormat'方法中使用'return $(cellObject.html())。attr(「originalValue」);'getCell'方法獲得html –

+0

@Imran:不客氣!有很多方法來實現這個要求。我很奇怪你在unformatter中使用了'.attr(「originalValue」)''。我假設你在'cellattr'裏設置了你沒有發佈的屬性。這種方式可能是一種可能的實現。如果你使用'datatype:「local」'或者使用'loadonce:true',另一種方法就可以工作。 unformatter的'option'參數包含'rowId'和'colModel''屬性。所以你可以使用var rowdata = $(this).jqGrid(「getLocalRow」,options.rowId);'得到rowdata和'rowdata [option.colModel.name]'來獲得列值。 – Oleg

相關問題