jqgrid不显示特殊符号 [英] jqgrid doesnot display special symbols

查看:128
本文介绍了jqgrid不显示特殊符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要jqgrid在某些列中显示一些特殊字符,例如"<test>",尝试使用autoencode=true,但是它将所有列更改为HTML编码,就像我在其他一些列中没有按钮一样需要编码,我们可以为特定列设置自动编码吗?有什么想法吗?

I need jqgrid to display some special characters like "<test>" in some of the columns, tried using autoencode=true but it changed all the column to HTML encoding, like I had buttons in some other columns which don't need encoding, can we set autoencode for specific columns? Any ideas?

我使用了oleg提议的格式化程序,但是遇到一个问题,即我在cols中有按钮,我需要在编辑模式之间切换为保存",保存并完成"和取消"发布代码,但是我不确定如何在编辑"模式下隐藏/取消隐藏按钮之间进行切换:

I have used the formatter as proposed by oleg,but I ran into issue where I had buttons in cols, where i need to toggle between edit mode to 'save',save and finished' and 'cancel' i am posting the code but I am not sure on how to toggle between hide/unhide the buttons in Edit mode:

网格设置:

            $("#list").jqGrid({
            url: '<%= Url.Action("JSONData","CompanyInfo")%>',
            datatype: 'json',
            colNames: ['ID', 'Company', 'Address' , 'Employers ', ''],
            colModel: [
                { name: 'ID', index: 'ID', align: 'left', sortable: false, editable: true, hidden: true },
                { name: 'Company', index: 'Company', align: 'left', sortable: false, editable: false, formatter: ConvertLineChartoBR },
                { name: 'Address', index: 'Address', editoptions: { size: 100 }, align: 'left', sortable: false, editable: true, edittype: 'textarea', formatter: ConvertLineChartoBR, unformat: ConvertLineChartoN }, 
                { name: 'Employers', index: 'Employers', editoptions: { size: 100 }, align: 'left', sortable: false, editable: true, edittype: 'textarea' },
                { name: 'act', index: 'act', editable: false, sortable: false, fixed: true, formatter: setupEdit}],
            pager: $('#pager'),
            autowidth: true,
            shrinkToFit: true,
            rowNum: currRecords,
            rowList: [5, 10, 20, 50],
            recordtext: "View Records {0} - {1} of {2}",
            emptyrecords: "No records to view",
            pgtext: "Page {0} of {1}",
            sortorder: "desc",
            viewrecords: true,
            autoencode: true,
            caption: 'Test'
        });

SetupEdit(用于格式化程序)

SetupEdit(For formatter)

      function setupEdit(cellvalue,options,rowObject) {

      var btnSave = "<input type='button' value='Save' style='display:none' onclick=\"$('#list').jqGrid('saveRow', '" + options.rowId + "', null,  '<%= Url.Action("GridSave","Company")%>', null, aftersavefunc);\" />";
      var btnSaveFinished = "<input type='button' value='Save & Finish' style='display:none' onclick=\"$('#list').jqGrid('saveRow', '" + options.rowId + "', null, '<%= Url.Action("GridSaveFinished","Company")%>', null, aftersavefunc);\" />";
      var btnCancel = "<input type='button' value='Cancel' style='display:none' onclick=\"$('#list').jqGrid('restoreRow', '" + options.rowId + "', aftercancelfunc);\" />";
      var Edit =  "<input type='button' value='Edit' class='editButton' onclick=\"$('#list').jqGrid('editRow','" + options.rowId+ "',false,oneditfunc);\" />";
        return btnSave + btnSaveFinished + btnCancel + Edit;
    }

OnEdit(在编辑"按钮上单击)

OnEdit(On Edit button click)

 function oneditfunc(result, x) {
  // I need to unhide the button of the last column where buttons are populated in setupEdit
  // On Edit click, i need to enable btnSave,btnSaveFinished and btnCancel
  //Again on aftersavefunc/aftercancelfunc i need to reset back the column value to display on Edit button
 }

推荐答案

不幸的是,您不能仅为一列设置autoencode: true.

Unfortunately you can't set autoencode: true only for one column.

我认为您真正的问题来了,因为您在创建按钮的列中以错误的方式放置了HTML标记.可能您将HTML标记作为数据的一部分放置了,这不好.更好的方法是使用自定义格式化程序.在这种情况下,您应该将 data 放在按钮列的JSON输入中,例如,格式化程序可以将其用作按钮的文本.如果按钮需要相同的文本,则按钮列的数据可以为空.例如

I think that your real problem come because you place the HTML markup in the wrong way in the column where you create buttons. Probably you place the HTML markup as the part of data, which is not good. The better way is to use custom formatters. In the case you should place in JSON input for the button column only the data which can be used by formater for example as the text of the buttons. If you need the same text for buttons you can have empty data for the button column. For example

formatter: function () {
    return "<span class='ui-icon ui-icon-plus'></span>";
}

在这种情况下,您可以毫无问题地使用autoencode: true.这些按钮将根据需要显示,并且<test>之类的文本将被编码并正确显示.

In the case you can use autoencode: true without any problems. The buttons will be displayed as needed and the texts like <test> will be encoded and correctly displayed.

已更新:您可以使用我在许多旧答案中都使用过的getColumnIndexByName:

UPDATED: You can use getColumnIndexByName which I used in many my old answers:

var getColumnIndexByName = function (grid, columnName) {
        var cm = grid.jqGrid('getGridParam', 'colModel'), i, l = cm.length;
        for (i = 0; i < l; i++) {
            if (cm[i].name === columnName) {
                return i; // return the index
            }
        }
        return -1;
    };

它可以帮助您按列获取colModel中列的索引.例如,使按钮外观与您可以使用的jQuery UI风格相对应

It helps you to get the index of column in the colModel by the column. For example to make the buttons looks corresponds to the jQuery UI style you can use

loadComplete: function () {
    var iAct = getColumnIndexByName ($(this), 'act');
    $(this).find("tbody>tr.jqgrow>td:nth-child(" + (iAct + 1) +
        ")>input[type='button']").button();
}

让我们知道该行号,并希望获取您放置在行为"列中的按钮.然后,您需要从那里显示一些内容或隐藏其他内容.您可以使用以下代码片段:

Let us you know the rowid and want to get the buttons which you placed in the column 'act'. Then you need to show some from there or hide other. You can use the following code fragment:

var iAct = getColumnIndexByName ($(this), 'act'),
    $td = $('#' + $.jgrid.jqID(rowid) + ">td:nth-child(" + (iAct + 1) + ")"),
    $save = $td.find(">input[value='Save']"),
    $saveAndFinish = $td.find(">input[value='Save & Finish']"),
    $cancel = $td.find(">input[value='Cancel']"),
    $edit = $td.find(">input[value='Edit']");
$save.show();
$saveAndFinish.show();
$cancel.show();
$edit.hide();

我建议您使用带有工具提示的图标,而不是按钮中的文本来保存网格中的位置.

I would recommend you to use icons with tooltips instead of texts in the buttons to save place in the grid.

这篇关于jqgrid不显示特殊符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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