Author Topic: how to save the data from param query grid to database  (Read 20453 times)

kavyasetty

  • Newbie
  • *
  • Posts: 25
    • View Profile
how to save the data from param query grid to database
« on: November 25, 2013, 04:42:22 pm »
i am using JSON data to pass the data to paramquery grid and it is displayed on grid perfectly. but my question is that if there are any changes in the data via grid.. how can it be captured and how to pass the data form pqgrid to controller as it has to be saved to database on click of a button .

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: how to save the data from param query grid to database
« Reply #1 on: November 25, 2013, 04:54:32 pm »
Use JSON.stringify method to convert JSON data of grid into string and send it to server using $.ajax.

Code: [Select]
  var data = JSON.stringify(dataModel.data);
  $.ajax({url: url, data: data});

kavyasetty

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: how to save the data from param query grid to database
« Reply #2 on: November 25, 2013, 05:19:13 pm »
thanks for the reply.
i tried the above. it dint work to get the data from pqgrid.

the scenario is as follows.

i have a button called save . so when i click the button the pqgrid data must be captured and stored in var data.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: how to save the data from param query grid to database
« Reply #3 on: November 26, 2013, 09:10:33 am »
Do you get error?

Could you please post your source code of the grid including the source code in the button.

kavyasetty

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: how to save the data from param query grid to database
« Reply #4 on: November 26, 2013, 10:57:35 am »
thanks for the reply.
the code that you have posted worked for me. I had made mistake with the syntax.

i have another question ,

var dataCell = $( "#fragment-1" ).pqGrid( "getEditCellData" );
          alert('data in cell  '+dataCell.toString())

here i am able to get the content of the cell. But how is it possible to get the row and column index of this cell??


kavyasetty

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: how to save the data from param query grid to database
« Reply #6 on: December 04, 2013, 02:50:40 pm »
I am using the below code to get the data from the grid and pass it to the controller,

 var data = JSON.stringify(dataModel.data);
  $.ajax({url: url, data: data});

i am able to capture the data from the grid ,but when i am passing the data via the url and trying to retrieve it in my servlet i am only able to get the data of 1st row of the grid. but i have data in 10 rows

forwheeler

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: how to save the data from param query grid to database
« Reply #7 on: December 04, 2013, 07:15:41 pm »
I get the row by the row index and build by json based on my model. This works for me so far.

Code: [Select]
                var row = ui.rowIndx;
                jsonstring = { "ID": ui.data[row].ID, "FiscalYear": ui.data[row].FiscalYear };

                Update(JSON.stringify(jsonstring));//send whole row in json to Update function


anurag

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: how to save the data from param query grid to database
« Reply #8 on: March 06, 2014, 02:16:25 am »
var data = JSON.stringify(dataModel.data); in this i am getting error as dataModel not defined....
i have used the sample code
$('#button1).click(function(){
var data = JSON.stringify(dataModel.data);
  $.ajax({url: url, data: data});
});
as my idea is that when i press this button than i get a JSON which i can send....

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: how to save the data from param query grid to database
« Reply #9 on: March 06, 2014, 05:43:20 am »
dataModel has a special meaning, it's name of the option in pqGrid.

http://paramquery.com/api#option-dataModel

anurag

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: how to save the data from param query grid to database
« Reply #10 on: March 06, 2014, 06:40:29 pm »
yes sir but i am unable to get how can i use dataModel.data in jsonstringfy() function.....as standalone....because i can only used it as
$( ".selector" ).pqGrid( "option", "dataModel", { data: dataSales } );
and now if i do something like this.....var t1=dataModel.data;
Than i get error...can you please let me know the correct way..

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: how to save the data from param query grid to database
« Reply #11 on: March 06, 2014, 06:59:11 pm »
you can get reference of dataModel

Code: [Select]
var dataModel = $grid.pqGrid( "option" , "dataModel");
var data = dataModel.data;

or dataModel.data directly

Code: [Select]
var data = $grid.pqGrid( "option" , "dataModel.data");

anurag

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: how to save the data from param query grid to database
« Reply #12 on: March 06, 2014, 08:13:27 pm »
Thanks a lot...sir :)

nazgarel

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: how to save the data from param query grid to database
« Reply #13 on: May 19, 2014, 07:16:46 pm »
Hi,
is it possible to sort the dataModel befor doing:

Code: [Select]
var data = JSON.stringify(dataModel.data);
i want to sort it by sortIndx: "Name".