0

How can I track which row is edited when user edited a editable textarea in jqgrid.

$("#accJqgrid").jqGrid({
    url: path,
    postData: { deviceId: deviceId, loadId: 'Hardware' },
    datatype: 'json', 
    mtype: 'POST',
    width: 650,
    height: 150,
    colNames: ['', 'ID', '', '', 'Description', '', '', 'Comments', 'Delete'],
    autowidth: true,
    colModel: [
        { name: 'state', width: 30, sortable: false, hidden: true },
        { name: 'ID', width: 30, sortable: false, hidden: true },
        { name: 'catalogId', width: 30, sortable: false, hidden: true },
        { name: 'Save', width: 30, sortable: false, formatter: saveAccessoryData },
        { name: 'Description', width: 250, sortable: false },
        { name: 'Search', width: 30, sortable: false, formatter: searchAccessory },
        { name: 'License', width: 0, sortable: false, hidden: true },
        { name: 'Comments', width: 380, sortable: false, edittype: 'textarea', editable: true, editoptions: { rows: "2", cols: "73", dataInit: function (elem) { $(elem).attr("maxlength", "250"); } } },
        { name: 'Delete', width: 50, sortable: false, edittype: 'checkbox', formatter: 'checkbox', editable: true, align: 'center', classes: 'deleteBackgroundColor' }
    ],
    rowNum: 50,
    pagination: true,
    rowList: [25, 50, 100],
    pager: $('#accJqgridpager'),
    gridComplete: function () {
        }
    },
    afterInsertRow: function (id, data) {
        jQuery('#accJqgrid').jqGrid('editRow', id);
    }
});

enter image description here

Nipuna
  • 6,846
  • 9
  • 64
  • 87
  • It seems to my no question about jqGrid. You have just textarea control and want to track the caret movement. See [here](http://stackoverflow.com/a/263796/315935) for example. Is it what you need? – Oleg Feb 01 '12 at 12:30
  • No i want to track which table row is edited. Since it is a textarea i cannot track if it is edited or not. – Nipuna Feb 02 '12 at 12:22
  • I still don't understand your question. First of all it's important to know which editing mode (inline editing, form editing or cell editing) you use? Do you use `multiselect: true` or not? It's better to post the jqGrid which you use. – Oleg Feb 02 '12 at 12:30
  • I changed the code. Please look into it. – Nipuna Feb 05 '12 at 12:13

1 Answers1

0

You can use beforeSelectRow callback to trace the current editing rows:

beforeSelectRow: function (rowid) {
    alert('rowid=' + rowid);
}

One remark to your code: I would you recommend never use afterInsertRow which make the filling of the jqGrid slowly. Instead of that you can add gridview: true option and call editRow inside of loadComplete or gridComplete:

loadComplete: function () {
    var $myGrid = $(this);
    $myGrid.find('>tbody>tr.jqgrow').each(function () {
        $myGrid.jqGrid('editRow', this.id);
    });
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • How do I know if the edit has been saved, in any of the cells, before submitting the grid? Right now, I am getting all the HTML code of a drop down when user is still in edit mode but submits the jqgrid by clicking a save button. – b.g Dec 19 '16 at 13:07
  • @b.g: You can use `getGridParam` to get `savedRow` parameter. The parameter contains array of elements. Every element corresponds the currently editing row. The exact format of the elements from `savedRow` depends on the version of jqGrid, which you use, and from the editing mode (cell editing or inline editing). You can use `savedRow` to detect which rows are currently editing. – Oleg Dec 19 '16 at 13:46