ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: svk123 on September 04, 2014, 01:56:20 pm

Title: addrow calling editrow and update
Post by: svk123 on September 04, 2014, 01:56:20 pm
Dear Sir,

Please find below code for addrow and editrow. Upon clicking the add row button, call is going to editrow as expected, but it is also going to update. This is adding a blank row in my paramgrid before I am able to enter any data. I would appreciate if you could help me in finding the error. This started happening after upgrading to paramquerypro 2.1.0.

Code: [Select]
       
function addRow($grid) {
            //alert("inadd");
            if (isEditing($grid)) {
                return false;
            }
            //append empty row in the first row.
            var today = new Date();
            var dd = today.getDate();
            var mm = today.getMonth() + 1; //January is 0!
            var yyyy = today.getFullYear();

            if (dd < 10) {
                dd = '0' + dd
            }

            if (mm < 10) {
                mm = '0' + mm
            }

            today = dd + '/' + mm + '/' + yyyy;                           
            var rowData = { scsno: "", ItemCd: "", Descript: "", Qty: 0.0,  Note: "",  FFRFlg: "", Rowid: "" }; //empty row template
            $grid.pqGrid("addRow", { rowIndxPage: 0, rowData: rowData });
           
            var $tr = $grid.pqGrid("getRow", { rowIndxPage: 0 });
           
            if ($tr) {
                //simulate click on edit button.
                $tr.find("button.edit_btn").click();
               
            }
           
        }

        //called by edit button.
        function editRow(rowIndx, $grid) {
            //alert("in edit");
            $grid.pqGrid("addClass", { rowIndx: rowIndx, cls: 'pq-row-edit' });
            $grid.pqGrid("editFirstCellInRow", { rowIndx: rowIndx });

            //change edit button to update button and delete to cancel.
            var $tr = $grid.pqGrid("getRow", { rowIndx: rowIndx }),
                $btn = $tr.find("button.edit_btn");
            $btn.button("option", { label: "Update", "icons": { primary: "ui-icon-check" } })
                .unbind("click")
                .click(function (evt) {
                    evt.preventDefault();
                    return update(rowIndx, $grid);
                });
            $btn.next().button("option", { label: "Cancel", "icons": { primary: "ui-icon-cancel" } })
                .unbind("click")
                .click(function (evt) {
                    $grid.pqGrid("quitEditMode");
                    $grid.pqGrid("removeClass", { rowIndx: rowIndx, cls: 'pq-row-edit' });
                    $grid.pqGrid("refreshRow", { rowIndx: rowIndx });
                    $grid.pqGrid("rollback");
                });
        }

Thanks,
SVK
Title: Re: addrow calling editrow and update
Post by: paramvir on September 04, 2014, 06:39:51 pm
Addition of blank row is as expected when clicked on add row button.

However if the update function is unnecessarily being called, put a break point in the beginning of update function and check the stack trace which would lead you to the calling function.
Title: Re: addrow calling editrow and update
Post by: svk123 on September 05, 2014, 02:57:59 pm
I replaced paramquery 2.1.0 by 2.0.4 and the error went away. There was no change in my code. The call to update is going from the editrow automatically even after clicking just the add row button in 2.1.0.
Code: [Select]
$btn.button("option", { label: "Update", "icons": { primary: "ui-icon-check"} })
            .unbind("click")
            .click(function (evt) {
                evt.preventDefault();
               return update(rowIndx, $grid);
            });
Title: Re: addrow calling editrow and update
Post by: paramvir on September 08, 2014, 08:15:27 pm
I didn't find anything wrong with your code; also checked the online demo with 2.0.4

Could you please provide a jsfiddle or a test case to reproduce the issue.