Search code examples
jqueryjqgrid

jqgrid inline add


Is is correct that jqGrid doesn't currently contain an inline add.

I'm trying to get this working from:

http://www.trirand.net/forum/default.aspx?g=posts&t=212

There are a couple of examples there but they're not working quite as I would like.

Anybody know of a good example


Solution

  • Try this:

    pager: '#id_pager',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"...",
    cellEdit: true,
    editurl:"....",
    
    beforeSelectRow: function (id) {
        if (id !== lastSel) {
            jQuery("#id_grid").jqGrid('restoreRow', lastSel);
            lastSel = id;
        }
        return true;
    },
    onSelectRow: function (id, iRow, iCol, e) {
        jQuery("#id_grid").jqGrid('editRow', id, true, function(){
            jQuery("input, select").focus();
        });
        return;
    }
    

    And add a button with navButtonAdd:

    .navButtonAdd("#id_pager", {
        caption: "",
        buttonicon: "",
        onClickButton: function () {
            var datarow = { id: "", name: "", address: "" };
            var su = jQuery("#id_grid").addRowData("X", datarow, "first");
            if (su) { jQuery("#id_grid").setSelection('X'); }
        },
        position: "last"
    });
    

    Don't forget for add editable: true, at every colModel. I hope can help your problem. Thanks