jQWidgets Forums
jQuery UI Widgets › Forums › Grid › how add each individual row tojqxGrid?
Tagged: addrow, data adapter, dataadapter, grid, jqxDataAdapter, jqxgrid
This topic contains 3 replies, has 2 voices, and was last updated by Adarsha 10 years, 9 months ago.
-
Author
-
Hi ,
I have a scenario. I will create a jqxGrid dynamically when user makes some selection and click on a button (lets say “Create”).
When user clicks on create a grid is created and a row wíth the selection made before “create”.
The scenario is, user is allowed to make another selection and click on “create”. when he makes that new selection it has to be added at the bottom of previous selection in the grid.
I use ‘addrow’ and created the record using JSON. but an empty row is created. Below is the code.. can you please correct my code
if (calselgrid_initialize == false){
var data = ‘[{‘+ ‘”fweek”:’ + ‘”‘ + from_week +'”,’ + ‘”tweek”:’ + ‘”‘ + to_week + ‘”,’ + ‘”remks”:’ +'”‘ + category + ‘”‘ +’}]’;
var source =
{
localdata: data,
datatype: “json”,
datafields:
[
{ name: ‘com’, type: ‘string’ },
{ name: ‘fweek’, type: ‘string’ },
{ name: ‘tweek’, type: ‘string’ },
{ name: ‘remks’, type: ‘string’ }
]
};
var dataAdapter = new $.jqx.dataAdapter(source);
$(“#jqxcalselgrid”).jqxGrid({
theme: ‘arctic’,
width:500,
source: dataAdapter,
selectionmode: ‘multiplecellsadvanced’,
autoloadstate: true,
editmode: ‘click’,
autoheight: true,
columns: [
{
text: ‘Comd’,
columntype: ‘button’,
datafield: ‘com’,
width: 50,
cellsrenderer: function ()
{
return “X”},buttonclick: function(test) {
var id = $(“#jqxcalselgrid”).jqxGrid(‘getrowid’, test);
var commit = $(“#jqxcalselgrid”).jqxGrid(‘deleterow’, id);
var rowcount = $(‘#jqxcalselgrid’).jqxGrid(‘getrows’)
if (rowcount.length == 0)
{
calselgrid_initialize = false;
}
}
},
{ text: ‘From Week’, datafield: ‘fweek’},
{ text: ‘To Week’, datafield: ‘tweek’},
{ text: ‘Remarks’, width: 200, datafield: ‘remks’}
]
});
calselgrid_initialize = true;
}else{
var datarow = $(‘#jqxcalselgrid’).jqxGrid(‘getrows’);
var row = {};
row[“com”] = “X”;
row[“fweek”] = from_week;
row[“tweek”] = to_week;
row[“remks”] = category;
var source =
{
localdata: row,
datatype: “json”,
datafields:
[
{ name: ‘com’, type: ‘string’ },
{ name: ‘fweek’, type: ‘string’ },
{ name: ‘tweek’, type: ‘string’ },
{ name: ‘remks’, type: ‘string’ }
]
};
var dataAdapter = new $.jqx.dataAdapter(source);
var commit = $(“#jqxcalselgrid”).jqxGrid(‘addrow’, null, dataAdapter);
}can any one please help…:(
Hello adarsha,
It is wrong to pass a dataAdapter instance to addrow. Here is how your code should look like:
... } else { var datarow = $('#jqxcalselgrid').jqxGrid('getrows'); var row = {}; row["com"] = "X"; row["fweek"] = from_week; row["tweek"] = to_week; row["remks"] = category; var commit = $("#jqxcalselgrid").jqxGrid('addrow', null, row); }
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks Dimitar. it worked!!!
-
AuthorPosts
You must be logged in to reply to this topic.