jqGrid change formatter of cell when cell has no value

早过忘川 提交于 2019-12-18 09:33:46

问题


I have a jqGrid in which one of the columns has set formatter as hyperlink below

{ name: 'IDNumber', index: 'IDNumber', classes: 'hyperlink',
    search: true, stype: 'text',
    formatter: 'showlink', formatoptions: { baseLinkUrl: '#'} },

when a cell does not have IDNumber value I want to change the formatter to string .

The reason why I want to do is when cell has no value and having link as formatter it is not displaying the gridline


回答1:


The formatter showlink produce <a> element for every input data which are strings (even empty string) or number.

I am not full sure that I understand correctly what you want.

If I understand you correctly you need to make the link "clickable" even if the cell contains empty string. To do so you can replace all empty strings in the column to something like "&nbsp;&nbsp;&nbsp;".

One more option which I can suggest you is to use my dynamicLink formatter which I described in the answer. It's very simple, but more powerful as predefined formatter showlink.

The demo shows how you can use it. The column

{ name: "mylink", width: 60, sortable: false,
    formatter: "dynamicLink",
    formatoptions: {
        cellValue: function (cellValue, rowId, rowData, options) {
            return cellValue !== "" ?
                cellValue :
                "<span style='color:red'>empty link</span>";
        },
        url: function (cellValue, rowId, rowData) {
            return '/Store/AddToCart?id=' + rowId + '?' +
                $.param({
                    name: rowData.name
                });
        }
    } }

allows to define custom cell value and the URL used in the link. The source code of the formatter you can find here. The demo displays the grid

where I placed some custom text (red text "empty link") instead of empty string.



来源:https://stackoverflow.com/questions/17218326/jqgrid-change-formatter-of-cell-when-cell-has-no-value

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