jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Grid addrow function almost works
Tagged: addrow grid, angular grid, angular2 grid, bootstrap grid, javascript grid, jquery grid, jqwidgets grid, jqxgrid
This topic contains 5 replies, has 2 voices, and was last updated by Weibing 8 years, 7 months ago.
-
Author
-
K I’m stumped…
Here’s my form
myform = $(‘#newComputer’);I grab all the data from my form. I know this works cuz I can alert(rowData) and it looks ok.
var rowData = JSON.stringify(myform.serializeObject());When I try and use rowData in the addrow function all I get is an empty row being added to my grid. However, when I copy the output of alert(rowData) and manually paste into a variable and run the same addrow function below it works perfectly. Is the variable rowData different than the output of alert(rowData)?
$(“#hardware_grid”).jqxGrid(‘addrow’, null, rowData)
I hope this makes sense.
Regards and Thank you.
Weibing
Hello Weibing,
You should set Object(or Array) to this row as second parameter to ‘addrow’ method.
Please, provide us small example if you still have same issue.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comThanks Hristo.
I’m trying to write something that resembles an existing sample, shown below
// create new row.
$(“#addrowbutton”).on(‘click’, function () {
var datarow = generaterow();
var commit = $(“#jqxgrid”).jqxGrid(‘addrow’, null, datarow);
});Seems straight forward. My version creates the proper key value format,
var rowData = JSON.stringify(myform.serializeObject());Here’s what rowData produces if I console.log or alert() the output.
{“computerId”:””,”TemplateId”:”68″,”Make”:”Lenovo”,”Model”:”X200″,”Processor”:”Intel Core 2 Duo P8700 (2.53GHz)”,”Memory”:”2048″,”MemConfig”:”1x2GB;1x2GB”,”Drive”:”240GB SSD”,”Rom”:”DVD-ROM/CD-RW Multi”,”Acquired”:”02-01-2010″,”DeviceType”:””,”LSBC”:”qqqqqqqqq”,”Serial”:””,”ProductNumber”:””,”Mac”:””,”AlternateName”:””,”isRetired”:”false”}
If I just paste this info into a variable it works fine i.e.
rowData = {“computerId”:””,”TemplateId”:”68″,”Make”:”Lenovo”,”Model”:”X200″,”Processor”:”Intel Core 2 Duo P8700 (2.53GHz)”,”Memory”:”2048″,”MemConfig”:”1x2GB;1x2GB”,”Drive”:”240GB SSD”,”Rom”:”DVD-ROM/CD-RW Multi”,”Acquired”:”02-01-2010″,”DeviceType”:””,”LSBC”:”qqqqqqqqq”,”Serial”:””,”ProductNumber”:””,”Mac”:””,”AlternateName”:””,”isRetired”:”false”}
But the code below doesn’t work. The grid adds an empty row, like rowData is empty {}. Is there a chance the first line is taking too long to populate rowData and the second line runs with an empty variable? I’m a total noob, so I appreciate the help. Thanks.
var rowData = JSON.stringify(myform.serializeObject());
var commit = $(“#hardware_grid”).jqxGrid(‘addrow’, null, rowData)
Here’s my addrow code copied from my source.
addrow: function (rowid, rowdata, position, commit) {
var computerData = $(‘#newComputer’).serialize();//grab all form fields
$.ajax({
url: ‘getDetails.cfc?method=’addComputer’&’ + computerData,
type:”POST”,
async: false,
success: function(response){
commit(true);
alert(rowdata);},
error : function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
alert(‘damn’);
commit(false);
}
});Hello Weibing,
Try to use this:
var rowData = myform.serializeObject();
instead of “var rowData = JSON.stringify(myform.serializeObject());”Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comYeah..that worked. Thanks for helping out a rookie. You rock.
-
AuthorPosts
You must be logged in to reply to this topic.