如何在jqGrid 4.0中合并单元格 [英] How to merge cells in jqGrid 4.0

查看:69
本文介绍了如何在jqGrid 4.0中合并单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在jqGrid中合并"单元格,也就是说,我想使特定行的单元格具有colspan = 2(或更多).到目前为止,我已经可以使用列模型中的 cellattr 选项使边框正常工作,如下所示:

I've been trying to "merge" cells in a jqGrid, that is, I want to make cells for specific rows have a colspan=2 (or more). So far I've been able to get the borders to work properly using the cellattr option in the column model with something like this:

colModel = { name: "a", width=50, 
             cellattr: function(rowId, tv, rawObject, cm, rdata) {
                          if (rowId < 5) { return 'sytle="border-right:0px"'; } },

             name: "b", width=50, 
             cellattr: function(rowId, tv, rawObject, cm, rdata) {
                          if (rowId < 5) { return 'sytle="border-left:0px"'; } } };

这只是删除了我要合并的单元格的边框(第5行的a& b).但是,如果我将文本添加到任何这些框中,则text-align显然将无法正常工作,并且如果文本大于50像素,则会被截断.

This just removes the border for the cells that I want to merge (a & b up to line 5). But if I add text to any of these boxes text-align will obviously not work properly and the text just gets cut off if it is larger than 50 pixels.

我可以做一些疯狂的事情,将所有文本切成两半,然后分别将每个半部分分别添加到右对齐和左对齐下的"a"和"b"列中,以进行居中对齐.但是,似乎应该有更好的方法.

I could do some crazy thing where I do center-align by cutting all the text in half and add each half to column "a" and "b" under right-align and left-align respectively. However, there seems like there should be a better way.

推荐答案

我发现您的问题非常有趣,因此我+1.

I find your question very interesting, so +1 from me.

在我看来,colspan=2的用法才是您真正需要的.要使具有colspan=2的行中的列数相同,我建议隐藏该行中的下一个<td>元素:

It seems to me that the usage of colspan=2 is what you really need. To have the same number of the columns in the rows having colspan=2 I suggest to hide the next <td> element in the row:

{
    name:'a',index:'a', width:50,
    cellattr: function(rowId, tv, rawObject, cm, rdata) {
        if (Number(rowId) < 5) { return ' colspan=2' }
    }
},
{
    name:'b',index:'b', width:50,
    cellattr: function(rowId, tv, rawObject, cm, rdata) {
        if (Number(rowId) < 5) { return ' style="display:none;"' }
    }
}

我只测试了几次实现,但似乎可行:

I tested the implementation only a few time, but it seems to work:

您可以在此处观看演示.

更新:另一个答案显示了如何在jqGrid中使用rowspan属性.

UPDATED: Another answer shows how can be used rowspan attribute in jqGrid.

这篇关于如何在jqGrid 4.0中合并单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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