Search code examples
jqgridfree-jqgrid

jqgrid generate unique rowid when add inline rows


15.1 pleas this demo

  [1]: https://jsfiddle.net/dnfk8hmr/53/

i want when add new record to grid generate unique rowID when remove rowID jgrid generate unique rowID with jqg2 ,jqg3 iam dont need this .i want Custom generate unique rowID

.jqGrid('inlineNav',
                {
                    edit: true, add: true, save: true, cancel: true,
                    addParams: {
                        position: "last", //ردیف‌های جدید در آخر ظاهر می
                      //  rowID: '_empty',
                        useDefValues: true,

                    },

                });

Solution

  • One can define rowID as callback function. For example, you can use

    addParams: {
        position: "last",
        rowID: function (options) {
            return 123 + $.jgrid.guid++;
        },
        useDefValues: true
    }
    

    where 123 is the start value and $.jgrid.guid is just a counter provided by jqGrid. You can use of cause any other way to generate ids.

    The demo https://jsfiddle.net/OlegKi/dnfk8hmr/60/ demonstrates which meaning could have options parameter. It contains just all options of addRow method used in the current call. I used in the demo the code

    addParams: {
        position: "last",
        startId: 123, 
        rowID: function (options) {
            return options.startId + $.jgrid.guid++;
        },
        useDefValues: true
    }
    

    only to demonstrate, that one can use custom options almost anywhere in jqGrid.