jQWidgets Forums
jQuery UI Widgets › Forums › Grid › serializeJSONArray is not working
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 13 years ago.
-
Author
-
In a Div I am having Save Button having Id Save_Selected and a grid.I am trying to send all rows datas from view to controller(FamilyParentAdministrationController) in serialised way but not able to send.I can able to send one row data only not all rows.If any solution plz let me Know.
//Inside my View
//Inside another script
$(“#Save_Selected”).bind(‘click’, function () {
//debugger;
//var JsonData1 = $.serializeJSONArray($(‘#jqxgrid’).getrowdata());
rowcount = $(“#jqxgrid”).jqxGrid(‘getdatainformation’).rowscount;
//var dataRecord1 = new Array();
for (var i = 0; i < rowcount; i++) {var dataRecord1 = $("#jqxgrid").jqxGrid('getrowdata', i);
}
//var Data = new Array();
//Data= { PHNo: $('#PHNo').val(), FamilyParent: $('#FamilyParent').val(), marketingNames: $('#marketingNames').val(), LOB: $('#LOB').val() };
debugger;
$.ajax({
url: '/FamilyParentAdministration/Save',
type: 'POST',
//data:dataRecord1,data: $(jqxgrid).serialize(),//data,// { PHNo: $('#PHNo').val(), FamilyParent: $('#FamilyParent').val(), marketingNames: $('#marketingNames').val(), LOB: $('#LOB').val() },
success: function (result) {
//alert(result);
}
// serializeJSONArray: function (jsonData, key) {
// var data = $.toJSON(jsonData, null, key);
// data = data.split('&');
// var ret = [];
// var namevalue;
// for (var i = 0; i < data.length; i++) {
// if (data[i].indexOf('Actions') != -1 || data[i].indexOf('<INPUT') != -1)
// continue;
// namevalue = data[i].split('=');
// ret.push({ name: namevalue[0], value: namevalue[1] });
// }
// return ret;
// }
});Inside Contoller I have written
[HttpPost]
public ActionResult Save(FamilyParentAdministrationViewModel iModel) //imodel will hold serialised Json array datas.But not happening.
{
List cs = (new FamilyParentAdminstrationModel()).SaveFamilyParentAdminData(iModel);
//string message = string.Format(“Created user ‘{0}’ in the system.”, iModel.PHNo);
//return Json(new FamilyParentAdminstrationModel { PHNo = message });
//return Json(new FamilyParentAdminstrationModel {});
return Json(cs);
}Hi RajaniKantaPanda,
Unfortunately, jqxGrid currently does not support Data Export to JSON or any other data format. If you want to export the Grid’s data, you will need to handle functions like getrowdata which returns a single grid row. Then, for data serialization to JSON, you can take a look here: http://stackoverflow.com/questions/191881/serializing-to-json-in-jquery.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI can able to take single row data from view to contoller but i want to take every row data.How will i take.?
Datas are comining like [0]{name and namevalue,age and agevalue,…..},[1]{name and namevalue,age and agevalue,…..},…..
but i need like[0]{name and namevalue},[1]{age and agevalue},…..,[4]{name and namevalue},[5]{age and agevalue},…..name, age properties have been defined in viewmodel.Thats why when its hiting to controller’s method only 2 value is showing what ever has been defined in view model.But in grid those properties are repeated every time.Means for every rows.
Can you plz help me?Hi RajaniKantaPanda,
The following code will convert the selected rows into JSON
var selectedIndexes = $(“#jqxgrid”).jqxGrid(‘selectedrowindexes’);
var rows = [];
for (var m = 0; m < selectedIndexes.length; m++) {
rows[rows.length] = $("#jqxgrid").jqxGrid('getrowdata', m);
}var serializedData = JSON.stringify(rows);
The json2.js file can be downloaded from: https://github.com/douglascrockford/JSON-js/blob/master/json2.js
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.