2
votes

I am trying to use jqgrid inline edit function. But I got the whole html tags when inline editor is triggered. enter image description here

What could be the reason? Thanks.

Here is the jqgrid code:

$(document).ready(function () {

'use strict';
var grid;

grid = jQuery("#list2");
grid.jqGrid({

    editurl: "clientArray",
    datastr: topicjson,
    datatype: "jsonstring",
    height: "auto",
    loadui: "disable",
    colNames: [/*"id",*/"Items","nick","url"],
    colModel: [
    //{name: "id",width:1, hidden:true, key:true},
    {name: "elementName", width:250, resizable: false, editable: true},
    {name: "nick", width:250, resizable: false, editable: true},
    {name: "url",width:1,hidden:true}
    ],
    treeGrid: true,
    treeGridModel: "adjacency",
    caption: "jqGrid Demos",
    ExpandColumn: "elementName",
    //autowidth: true,
    rowNum: 100,
    //ExpandColClick: true,
    treeIcons: {leaf:'ui-icon-document-b'},
    jsonReader: {
    repeatitems: false,
    root: "response"
    },
    cellEdit: true,
    cellSubmit: "clientArray",
    onSelectRow: function(id){
    if(id && id!==lastSel){ 
    jQuery('#list2').restoreRow(lastSel); 
    lastSel=id; 
    }
    jQuery('#list2').editRow(id, true); 
    }   

});

});

1
Pictures are nice but code is better. - Musa
Comments are good, answers are better. - biajee
:P, you should post a comment if you update your post several hours later to notify prospective answerers. - Musa
Oh, I didn't know that editing a question will not notify the commenters. BTW, based on my understanding to jqGrid, if I know the answer to this question, all I need to see is the picture to figure out what the problem is. As a code forum, it's really really odd stackoverflow makes it easier to post a picture than a chunk of codes. - biajee

1 Answers

3
votes

It turns out you can use formatCell event to change cell content before editing. The return value is the content you want. For this particular case, the treeGrid has small image with all html tags in the cell. When you edit the cell, by default everything is displayed as a cell content. To fix it, you can do this:

  formatCell: function(rowid,cellname,value,iRow,iCol) {
    return whatever_you_want_to_be;
  }