Author Topic: problem to get rows added  (Read 6938 times)

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
problem to get rows added
« on: January 05, 2016, 09:23:54 pm »
Hi guys,

I'm French boy then sorry for my english language level.

What I ask is simple :p. Once I have added all my lines via the grid, I want get all rows added but i don't found this :(.

Please, somebody can help me to act ?

Thank you :)


This is my code :
toolbar: {
         items: [
            //...
            { type: 'button', icon: 'ui-icon-disk', label: 'Add all rows', cls: 'changes', listener:
               { "click": function (evt, ui) {
                  console.log(this); console.log(evt); console.log(ui);
                  saveChanges(this, evt, ui);
               }
               },
               options: { disabled: false }
            }
         //...
}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #1 on: January 06, 2016, 12:18:15 am »
You have to implement saveChanges function as well as server side code to commit the changes to the server as shown in this demo:

http://paramquery.com/pro/demos/editing_batch

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: problem to get rows added
« Reply #2 on: January 07, 2016, 10:22:54 pm »
I have TypeError: grid.saveEditCell is not a function

function saveChanges() {
   
      console.log(grid);
   
      //attempt to save editing cell.
      if (grid.saveEditCell() === false) {
         return false;
      }
      
      if ( grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid ) {

         var changes = grid.getChanges({ format: "byVal" });
         
         console.log(changes);
         
         
      }
    }



------

var grid = $("#montableauecriture").pqGrid(obj);

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #3 on: January 07, 2016, 11:58:06 pm »
jQuery object is returned by $("#montableauecriture").pqGrid(obj);

Code: [Select]
var $grid = $("#montableauecriture").pqGrid(obj);

where as javascript widget instance is returned by call to  pq.grid( "#grid_editing", obj );

Code: [Select]
var grid = pq.grid( "#montableauecriture", obj );

And the latter is used in saveChanges function as can be seen from the syntax:

Code: [Select]
grid.saveChanges();

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: problem to get rows added
« Reply #4 on: January 08, 2016, 02:40:05 pm »
Thanks for your answer.

In fact, I want use jQuery Object because my code is implemented in jQuery.

Is it possible to have the function " saveChanges() " of http://paramquery.com/pro/demos/editing_batch in " jQuery " code please ?

I wish you a good day and I thank you for your attention :).

Thank a lot of.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #5 on: January 08, 2016, 07:08:03 pm »
Of course, alternative way of writing grid.saveChanges() is $grid.pqGrid( 'saveChanges' );

Both can be used interchangeably, it depends upon your preference and availability of required variable i.e., grid or $grid.

http://paramquery.com/pro/tutorial#topic-methods

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: problem to get rows added
« Reply #6 on: January 11, 2016, 08:04:34 pm »
Hello " paramquery ",

Thanks for your answers that help me strongly. I think that it will be more simple that you translate this " javascript code " in " jquery code " please. (My " jquery object " is grid : I prefer the variable name " grid " to " $grid " ).

I wish you a good day and an excellent week.


function saveChanges() {
   
      console.log(grid);
   
      //attempt to save editing cell.
      if (grid.saveEditCell() === false) {
         return false;
      }
     
      if ( grid.isDirty() && grid.isValidChange({ focusInvalid: true }).valid ) {

         var changes = grid.getChanges({ format: "byVal" });
         
         console.log(changes);
         
         
      }
    }


Arnaud.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #7 on: January 11, 2016, 09:01:33 pm »
Arnaud

To repeat and make myself more clear, general syntax of widget instance is

Code: [Select]
instance.method_name( parameters );

and its jQuery equivalent is

Code: [Select]
$( ".selector" ).pqGrid( 'method_name', parameters );


Please check the below code in jQuery. Hope it helps.

Code: [Select]
function saveChanges() {
   
      console.log(grid);
   
      //attempt to save editing cell.
      if ($grid.pqGrid( 'saveEditCell' ) === false) {
         return false;
      }
     
      if ( $grid.pqGrid( 'isDirty' ) && $grid.pqGrid( 'isValidChange', { focusInvalid: true }).valid ) {

         var changes = $grid.pqGrid( 'getChanges', { format: "byVal" });
         
         console.log(changes);
                 
      }
    }
« Last Edit: January 11, 2016, 09:32:29 pm by paramquery »

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: problem to get rows added
« Reply #8 on: January 11, 2016, 10:59:38 pm »
Re-hello,

I'm sorry to return to you but I'm on the end with the function " saveChanges " but I block on the " $grid manipulation " in data submission. Here are " console.log " :

console.log($grid) ==> Object { 0: <div#montableauecriture.pq-grid.panel.panel-default.pq-disable-select>, length: 1, context: HTMLDocument → ecriture, selector: "#montableauecriture" }

console.log($grid.pqGrid( 'saveEditCell' )) ==> undefined

console.log($grid.pqGrid( 'isDirty' )) ==> false

Can you help me to have " $grid.pqGrid( 'getChanges', { format: "byVal" }); " with datas please ?

Thanks.

Arnaud.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #9 on: January 11, 2016, 11:31:42 pm »
Quote
Can you help me to have " $grid.pqGrid( 'getChanges', { format: "byVal" }); " with datas please ?

I'm not sure what is your question. Please look into the documentation for the getChanges method.

http://paramquery.com/pro/api#method-getChanges

For more details check its console.log

console.log ( $grid.pqGrid( 'getChanges', { format: "byVal" }) )
« Last Edit: January 11, 2016, 11:36:14 pm by paramquery »

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: problem to get rows added
« Reply #10 on: January 12, 2016, 02:09:22 pm »
function saveChanges() {
      
      console.log('---');

      console.log($grid.pqGrid( 'getChanges', { format: "byVal" })); //return Object { updateList: Array[0], addList: Array[0], deleteList: Array[0], oldList: Array[0] } instead of an Object with the datas of my grid (here are 0 anywhere in " changes ").

      console.log('true ? ' + $grid.pqGrid( 'isDirty' )); //return false instead of true

      console.log('true ? ' + $grid.pqGrid( 'isValidChange', { focusInvalid: true }).valid); //return true ==> it works

      console.log('false ? ' + ($grid.pqGrid( 'saveEditCell' ) === false)); //return false ==> it works

      console.log('---');   
    }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #11 on: January 12, 2016, 02:20:06 pm »
That means tracking is not working in your case.

Please ensure that you have turned on the below options:

1) trackModel: { on: true }, //to turn on the track changes.

2) dataModel: { recIndx: "dataIndx of primary key", ... } // http://paramquery.com/pro/api#option-dataModel-recIndx

Arnaud

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: problem to get rows added
« Reply #12 on: January 12, 2016, 07:10:44 pm »
THANKS !!!! IT WORKS !!!

I LOVE YOU SO MUCH !!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: problem to get rows added
« Reply #13 on: January 12, 2016, 07:17:45 pm »
You're welcome!