ParamQuery grid support forum

General Category => Help for ParamQuery Grid (free version) => Topic started by: kavyasetty on November 25, 2013, 04:42:22 pm

Title: how to save the data from param query grid to database
Post by: kavyasetty 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 .
Title: Re: how to save the data from param query grid to database
Post by: paramvir 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});
Title: Re: how to save the data from param query grid to database
Post by: kavyasetty 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.
Title: Re: how to save the data from param query grid to database
Post by: paramvir 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.
Title: Re: how to save the data from param query grid to database
Post by: kavyasetty 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??
Title: Re: how to save the data from param query grid to database
Post by: paramvir on November 26, 2013, 06:46:05 pm
use

http://paramquery.com/api#method-getEditCell

and

http://paramquery.com/api#method-getCellIndices
Title: Re: how to save the data from param query grid to database
Post by: kavyasetty 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
Title: Re: how to save the data from param query grid to database
Post by: forwheeler 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

Title: Re: how to save the data from param query grid to database
Post by: anurag 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....
Title: Re: how to save the data from param query grid to database
Post by: paramvir 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
Title: Re: how to save the data from param query grid to database
Post by: anurag 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..
Title: Re: how to save the data from param query grid to database
Post by: paramvir 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");
Title: Re: how to save the data from param query grid to database
Post by: anurag on March 06, 2014, 08:13:27 pm
Thanks a lot...sir :)
Title: Re: how to save the data from param query grid to database
Post by: nazgarel 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".