当单元格没有值时,jqGrid更改单元格的格式化程序 [英] jqGrid change formatter of cell when cell has no value

查看:96
本文介绍了当单元格没有值时,jqGrid更改单元格的格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jqGrid,其中的一列已将格式化程序设置为下面的超链接

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: '#'} },

当单元格没有IDNumber值时,我想将格式化程序更改为字符串.

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

推荐答案

格式化程序showlink为字符串(甚至是空字符串)或数字的每个输入数据生成<a>元素.

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.

如果我对您的理解正确,即使该单元格包含 empty 字符串,也需要使链接可点击".为此,您可以将列中的所有空字符串替换为"&nbsp;&nbsp;&nbsp;".

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;".

我可以建议您使用的另一种选择是使用我在答案中描述的dynamicLink格式化程序.它非常简单,但是作为预定义的格式化程序showlink更强大.

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
                });
        }
    } }

允许定义自定义单元格值和链接中使用的URL.您可以在此处找到格式化程序的源代码.演示显示网格

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.

这篇关于当单元格没有值时,jqGrid更改单元格的格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆