最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQgrid after save callback function - Stack Overflow

programmeradmin1浏览0评论

I have created a jQgrid and want it to call a callback function once a new row is added or some content is edited in the grid

jQuery("#list1").jqGrid({
        url: '/testGrid/sample?q=5', 
        datatype: "json", 
        mtype: 'POST',
        jsonReader: {
            page: "page",
            total: "total",
            root: "rows",
            records: "records",
            repeatitems: false,
            cell: "name",
            userdata: 'userdata'
        },
        width: 775,
          colNames: ['Salaried Employees', '# of FTEs', 'Budget', 'Actuals to Date', 'Invoice Salary'],
          colModel: [
            {name:'salEmp',index:'salEmp', width:100, align: 'left', width:100,editable:false,editrules:{required:true}},
            {name:'FTE',index:'FTE', width:100, align: 'center', editable:false,required:true,editrules:{required:true,number:true}},
            {name:'Budget',index:'Budget', width:100, align: 'right', width:100,editable:false,required:true,editrules:{required:true,number:true}},
            {name:'actDate',index:'actDate', width:100, align: 'right', align:"right",editable:false,required:true,editrules:{required:true,number:true}},
            {name:'invSal',index:'invSal', width:100, align:"right",editable:true,required:true,editrules:{required:true,number:true}}                                        
           ],
            rowNum: 5,
            rowList: [5, 10, 20],
            autoencode: true,
            ignoreCase: true,
            sortable: false,
            height: '100%',
            pager: jQuery('#pager1'),
            cellEdit: false,
            cellsubmit: 'remote',
            //cellurl: '/testGrid/sample',

            //call onclick of save
            editurl:"/testGrid/sample",
            gridview: true,
            reloadAfterSubmit:true
        })
        // Pager options for Subgrid
        .navGrid('#pager1',{
            add:false,
            edit:false,
            del:true,
            search:false,
            refresh:false,
            deltext: 'Delete'
        });
$('#list1').jqGrid('inlineNav','#pager1',{
            addtext: "Add",
            edittext: "Edit",
            savetext: "Save",
            canceltext: "Cancel",                       
            addParams: { 
                position: "afterSelected"
            },
            addedrow:'last'

        });

I have created a jQgrid and want it to call a callback function once a new row is added or some content is edited in the grid

jQuery("#list1").jqGrid({
        url: '/testGrid/sample?q=5', 
        datatype: "json", 
        mtype: 'POST',
        jsonReader: {
            page: "page",
            total: "total",
            root: "rows",
            records: "records",
            repeatitems: false,
            cell: "name",
            userdata: 'userdata'
        },
        width: 775,
          colNames: ['Salaried Employees', '# of FTEs', 'Budget', 'Actuals to Date', 'Invoice Salary'],
          colModel: [
            {name:'salEmp',index:'salEmp', width:100, align: 'left', width:100,editable:false,editrules:{required:true}},
            {name:'FTE',index:'FTE', width:100, align: 'center', editable:false,required:true,editrules:{required:true,number:true}},
            {name:'Budget',index:'Budget', width:100, align: 'right', width:100,editable:false,required:true,editrules:{required:true,number:true}},
            {name:'actDate',index:'actDate', width:100, align: 'right', align:"right",editable:false,required:true,editrules:{required:true,number:true}},
            {name:'invSal',index:'invSal', width:100, align:"right",editable:true,required:true,editrules:{required:true,number:true}}                                        
           ],
            rowNum: 5,
            rowList: [5, 10, 20],
            autoencode: true,
            ignoreCase: true,
            sortable: false,
            height: '100%',
            pager: jQuery('#pager1'),
            cellEdit: false,
            cellsubmit: 'remote',
            //cellurl: '/testGrid/sample',

            //call onclick of save
            editurl:"/testGrid/sample",
            gridview: true,
            reloadAfterSubmit:true
        })
        // Pager options for Subgrid
        .navGrid('#pager1',{
            add:false,
            edit:false,
            del:true,
            search:false,
            refresh:false,
            deltext: 'Delete'
        });
$('#list1').jqGrid('inlineNav','#pager1',{
            addtext: "Add",
            edittext: "Edit",
            savetext: "Save",
            canceltext: "Cancel",                       
            addParams: { 
                position: "afterSelected"
            },
            addedrow:'last'

        });
Share Improve this question edited Nov 24, 2019 at 21:27 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Jan 14, 2013 at 11:45 VarunVarun 5,05112 gold badges56 silver badges86 bronze badges 4
  • The code which you posted don't contain any editing. The answer on your question depend on which editing mode you want to use: cell editing, inline editing or form editing. Additionally jqGrid provide many options of usage of inline editing and form editing like inlineNav, formatter: "actions" etc. – Oleg Commented Jan 14, 2013 at 12:03
  • The callbacks which you need are different for different kind of editing modes and different implementation variants. So you have to decide first which editing mode and which implementation version more corresponds the requirements of your project. – Oleg Commented Jan 14, 2013 at 12:04
  • @Oleg - i will be using cell based editing eventually this is more of POC to explore jQgrid – Varun Commented Jan 14, 2013 at 12:43
  • What is "POC"? As I wrote before every implementation of editing provide callbacks, but the callbacks are different. So if you decide to use cell editing instead you need use another callbacks. Moreover you should specify more exact at what moment you need your callback by called: before editing started, directly after started, before saving, after saving etc. – Oleg Commented Jan 14, 2013 at 12:53
Add a ment  | 

1 Answer 1

Reset to default 8

inlineNav allows to specify the callbacks of editRow used for inline editing. To specify the callbacks one can use editParams and addParams.addRowParams options:

var myEditOptions = {
        keys: true,
        oneditfunc: function (rowid) {
            alert("row with rowid=" + rowid + " is editing.");
        },
        aftersavefunc: function (rowid, response, options) {
            alert("row with rowid=" + rowid + " is successfuly modified.");
        }
    };

$('#list1').jqGrid('inlineNav','#pager1', {
    addtext: "Add",
    edittext: "Edit",
    savetext: "Save",
    canceltext: "Cancel",                       
    addParams: { 
        position: "afterSelected",
        addRowParams: myEditOptions
    },
    addedrow: "last",
    editParams: myEditOptions
});
发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>