I am new to jqgrid. I have the following code to insert a new row when a tab key is pressed. It works for the most part of it. But when a new row is inserted, the focus is given to the second Column in that row instead of First column.
How do I solve this problem??
HTML:
<table id="list11"></table>
<!--<div id="paddtree"></div>-->
<label>press tab to add new row</label>
<script>
var selIRow = 1;
var lastsel2
jQuery("#list11").jqGrid({
// url:'d/${jobId}.htm',
datatype: "json",
colNames: ['First Name', 'Email ID', 'Phone Number'],
colModel: [
// {name:'id',index:'id', width:75, search:true, stype:'text' , search:true, sortable:true},
{name: 'firstName', width: 180, search: true, stype: 'text', sortable: true, editable: true, },
{name: 'email', index: 'email', width: 250, editable: true},
{name: 'phoneNumber', index: 'phoneNumber', width: 100, align: "right", editable: true,
editoptions: {
dataInit: function(elem) {
$(elem).focus(function() {
this.select();
})
},
dataEvents: [
{
type: 'keydown',
fn: function(e) {
var key = e.charCode || e.keyCode;
if (key == 9 || key == 15)//tab
{
var grid = $('#list11');
//Save editing for current row
grid.jqGrid('saveRow', selIRow, false, 'clientArray');
//If at bottom of grid, create new row
// alert(grid.getDataIDs().length);
if (selIRow++ == grid.getDataIDs().length) {
grid.addRowData(selIRow, {});
}
//Enter edit row for next row in grid
grid.jqGrid('editRow', selIRow, true, 'clientArray');
}
}
}
]
}, },
],
beforeRequest: function(data) {
var grid = $('#list11');
grid.addRowData(grid.jqGrid('getGridParam', 'records') + 1, {});
grid.jqGrid('editRow', selIRow, false, 'clientArray');
},
onSelectRow: function(id) {
if (id && id !== lastsel2) {
jQuery('#list11').jqGrid('restoreRow', lastsel2);
jQuery('#list11').jqGrid('editRow', id, true);
lastsel2 = id;
}
},
// editurl: "data/add.htm",
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "Candidates applied for <bold> ${job.getTitle()}</bold>",
// pager : "#paddtree",
emptyrecords: "new",
});
</script>
Thanks.
datatype: "json"
so it should beurl
options)? You don't definedediturl
. You specify in some places (but not everywhere)'clientArray'
asurl
. Do you want to modify the data only locally? Moreover you set focus of third column ('phoneNumber') and moreover in a wrong way, but you wrote "the focus is given to the second Column in that row instead of First column". What behavior you want to implement? – ProvisoURL
andEDITURL
but only here I have commented it out. – HyperaesthesiaeditRow
inonSelectRow
with saving on remote place (editurl: "data/add.htm"
), but don't save new added data at all or discard the data (save only locally) if one TAB pressed? – Proviso