free jQgrid 4.9.2, On delete confirmation box showing Id of dropdown instead text value

余生长醉 提交于 2019-12-07 23:59:28

It's difficult to reproduce your problem because there are no working demo with test data.

I suppose that you used before the code without formatter: 'select' and now you added the property to the column Consignee. Additionally you changed the data used as input for jqGrid from textes to values (ids). Thus you get now $(this).jqGrid('getCell', rowId, 'Consignee') the value instead of the text in the Delete dialog. Migration from free jqGrid 4.8.2 to 4.9.2 seems to me independent from the problem.

The solution of the problem seems to me in changing the code of beforeShowForm which you use in Delete form. After getting the value from the column Consignee (by using $(this).jqGrid('getCell', rowId, 'Consignee')) you have to convert the value to the text using editoptions.value property of the column. You use currently just value: eval('(' + g_oConsigneeList + ')') in your code. So it's unclear for me which format of data you use for value. In any way the usage of value: $.parseJSON('(' + g_oConsigneeList + ')') seems me better to have less security problems. To convert the value to the text you need to parse editoptions.value property. jqGrid allows you different forms of the value. If you use object form for example then you can use the following code

beforeShowForm: function ($form) {
    var $self = $(this), p = $self.jqGrid("getGridParam"),
        val = $self.jqGrid("getCell", p.selrow, "Consignee"),
        cm = p.colModel[p.iColByName.Consignee],
        editVal = cm.editoptions.value;
    $("td.delmsg", $form[0]).html("Do you really want delete the <b>   Consignee: " +
        editVal[val] + "</b>?");
}

If you use string form of editoptions.value property then you should replace the value editVal[val] to a little more complex code. You will need to split editoptions.value by ; first and to split every resulting element by : to have value to text mapping. Then you will need find the text which corresponds the value.

UPDATED: One more way to get the data from the cell in exactly the form which jqGrid display there is the following:

beforeShowForm: function ($form) {
    var $self = $(this), p = $self.jqGrid("getGridParam"),
        tr = $self.jqGrid("getGridRowById", p.selrow),
        $cell = $.jgrid.getDataFieldOfCell.call(this, tr, p.iColByName.Consignee);

    $("td.delmsg", $form[0]).html("Do you really want delete the <b>   Consignee: " +
        $cell.text() + "</b>?");
}

The helper method $.jgrid.getDataFieldOfCell get us the <td> element or an inner part of the cell if some wrapper are used. One cal then use $cell.text() to get the required data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!