我正在使用Coldfusion和jqgrid。免费jqgrid 4.8.0 colModel editoptions - 来自查询的动态值
有没有办法从查询结果中动态填充colModel editoptions?
我正在使用Coldfusion和jqgrid。免费jqgrid 4.8.0 colModel editoptions - 来自查询的动态值
有没有办法从查询结果中动态填充colModel editoptions?
如果您需要动态设置1:female;2:male
这样的选项,那么我想您会在指定的列中填充包含1或2的数据。所以你必须使用formatter: "select"
(见the documentation)。因此,你应该能够设置属性,如下面
{name: "sex", formatter: "select", editoptions: { value: "1:female;2:male" }}
如果你需要动态设置这样的选择,要加载来自服务器的有关editoptions.value
。
您可以使用的最原始的回调是beforeProcessing
。回调将在之前处理从服务器返回的数据将使用格式化程序显示。因此,您可以对formatoptions
或editoptions
进行任何更改。
如果服务器响应现在看起来像
{
"rows": [
{"id": 123, "name": "John", "sex": "2"},
{"id": 456, "name": "Mary", "sex": "1"}
]
}
那么你可以扩展服务器响应以下
{
"rows": [
{"id": 123, "name": "John", "sex": "2"},
{"id": 456, "name": "Mary", "sex": "1"}
],
"colModelExtentions": {
"sex": {"formatter": "select", "editoptions": {"value": "1:female;2:male"}}
}
}
在这样的数据,你指定的特定项目的一些变化colModel
直接在服务器响应中。在beforeProcessing
回调,其处理这些数据的实现可以看起来像
beforeProcessing: function (data) {
var cmName, cmExt = data.colModelExtentions, $self = $(this),
p = $self.jqGrid("getGridParam");
for (cmName in cmExt) {
// enumerate properties of colModelExtentions like sex
if (cmExt.hasOwnProperties(cmName)) {
$self.jqGrid("setColProp", cmName, cmExt[cmName]);
}
}
}
和colModel
定义"sex"
列像
{name: "sex", width: 50}
您将在the answer和this one找到有关该方案的更多细节。您可以扩展返回服务器的信息。在这种情况下,您可能需要另外拨打setColWidth
或setLabel
以动态应用列宽和列标题的文本。