如何包装jqGrid内容? [英] How to wrap jqGrid content?
问题描述
我想将内容包装在jqGrid中,格式如下:
输入字符串2013/05/28 10:54-默认-主题A添加了任务输出字符串2013/05/28 10:54-默认主题添加了任务
下面是我给出要在屏幕上显示的内容的代码
jQuery(#message").jqGrid({数据类型:本地",数据:resultSet,高度:250,宽度:960,可排序的:false,ignoreCase:是的,sortorder:"desc",colNames:[''],colModel:[{名称:内容",索引:内容",宽度:'10%',居中对齐',可排序的:false,搜索:假}],rowList:[10,20,30],传呼机:'#pager',rowNum:10,altRows:是的,altclass:"myclass",viewrecords:是的,});
我这样尝试过 nltobr
loadComplete:function(){for(var i = 0; i< resultSet.length; i ++){resultSet [i] .messageContent = nl2br(resultSet [i] .messageContent);}}
那是行不通的.
有什么方法可以根据第二髋关节进行包装吗?我也想加粗第一行.
var i,str,a;对于(i = 0; i< mydata.length; i ++){str = mydata [i] .note;如果(typeof str ==="string"){a = str.split("\ n");如果(长度> 1){a [0] =< strong>"+ a [0] +</strong>";mydata [i] .note = a.join("\ n");}}}
另一个演示演示了如何使用自定义格式化程序来执行相同的.如果使用jqGrid的 autoencode:true
选项,则应使用该方法.在演示中, note
列的格式设置为
formatter:函数(值){var a;if(value == null || value ==="){返回 ";} else if(typeof value ==="string"){a = value.split("\ n");如果(长度> 1){a [0] =< strong>"+ a [0] +</strong>";返回a.join("\ n");} 别的 {返回$ .jgrid.htmlEncode(value);}} 别的 {返回$ .jgrid.htmlEncode(value);}}
I want to wrap the content inside jqGrid which will be in the below format
Input string
2013/05/28 10:54 - Default - Subject A Task added
Output String
2013/05/28 10:54 - Default
Subject A Task added
Below is the code where I give the content to be displayed on screen
jQuery("#message").jqGrid({
datatype : "local",
data : resultSet,
height :250,
width : 960,
sortable : false,
ignoreCase : true,
sortorder : "desc",
colNames : [''],
colModel : [ {
name : 'content',
index : 'content',
width : '10%',
align : 'center',
sortable : false,
search : false
}],
rowList:[10,20,30],
pager : '#pager',
rowNum : 10,
altRows : true,
altclass:"myclass",
viewrecords : true,
});
I tried nltobr
like this
loadComplete : function() {
for (var i = 0; i < resultSet.length; i++) {
resultSet[i].messageContent = nl2br(resultSet[i].messageContent);
}
}
That is not working.
Is there any way to wrap based on second hipen? I also want to bold the first line.
First of all nltobr can be used in the server code and not inside of JavaScript callback method loadComplete
will will be executed after filling the grid. Seconds the callback loadComplete
will be called after the grid content will be placed in the grid. If you want make some modification of resultSet
data you should do this before the grid with the data are created.
You wrote about wrapping of content, but the usage of nltobr
and the text example which you posted shows that you have just new line character \n
inside of the text. It it is
The demo uses the text which you posted and contains \n
inside of the text. The results looks like you want
If you really need wrapping of the text then I recommend you to read the following answers: this one, this one and this one.
UPDATED: If you need make bold the first line of multiline content of some column you can insert <strong>
in the text. If you don't use autoencode: true
option of jqGrid then you can modify input data before creating jqGrid. For example the demo modifies content of note
column:
var i, str, a;
for (i = 0; i < mydata.length; i++) {
str = mydata[i].note;
if (typeof str === "string") {
a = str.split("\n");
if (a.length > 1) {
a[0] = "<strong>" + a[0] + "</strong>";
mydata[i].note = a.join("\n");
}
}
}
Another demo demonstrate how to use custom formatter to do the same. You should use the approach if you use autoencode: true
option of jqGrid. Th formatter of note
column are defined in the demo as
formatter: function (value) {
var a;
if (value == null || value === "") {
return " ";
} else if (typeof value === "string") {
a = value.split("\n");
if (a.length > 1) {
a[0] = "<strong>" + a[0] + "</strong>";
return a.join("\n");
} else {
return $.jgrid.htmlEncode(value);
}
} else {
return $.jgrid.htmlEncode(value);
}
}
这篇关于如何包装jqGrid内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!