Author Topic: addrow calling editrow and update  (Read 3710 times)

svk123

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 9
    • View Profile
addrow calling editrow and update
« 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
« Last Edit: September 04, 2014, 01:58:35 pm by svk123 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: addrow calling editrow and update
« Reply #1 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.

svk123

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: addrow calling editrow and update
« Reply #2 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);
            });
« Last Edit: September 05, 2014, 03:17:23 pm by svk123 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: addrow calling editrow and update
« Reply #3 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.