javascript - How to move cursor from Second Column to First Column in a new row in jqgrid -
i new jqgrid. have following code insert new row when tab key pressed. works part of it. when new row inserted, focus given second column in row instead of first column.
how solve problem??
html:
<table id="list11"></table> <!--<div id="paddtree"></div>--> <label>press tab 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 current row grid.jqgrid('saverow', selirow, false, 'clientarray'); //if @ bottom of grid, create new row // alert(grid.getdataids().length); if (selirow++ == grid.getdataids().length) { grid.addrowdata(selirow, {}); } //enter edit row 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 <bold> ${job.gettitle()}</bold>", // pager : "#paddtree", emptyrecords: "new", }); </script> thanks.
all have code add line e.preventdefault(); here:
if (key == 9 || key == 15)//tab { e.preventdefault(); ...
Comments
Post a Comment