jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Problem with addrow on an empty grid
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 11 years, 2 months ago.
-
Author
-
Hi Team,
I’m having a small problem with adding/deleting rows in a grid when the grid starts empty.
Basically i have a grid which reads from a DB using JSON.
The grid initializes with whatever is on the database for the customer i select. There are some which do not have any records yet and therefore the grid initializes blank.I then have an add and delete buttons to add items to the Grid. When i add an item the grid is populated with the information i want. But if i immediatly try to delete that row it does not retrieve the rowID and it not able to delete that row.
Basically my source is defined as:
var tbl_lgroupssites =
{
datatype: “json”,
data: { Action: “lgroupsSites”, lgs_id: ‘0’ },
datafields: [{name: ‘lgs_id’},{ name: ‘lgs_bcode’},{ name: ‘lgs_bdescription’},{ name: ‘lgs_rcode’},{ name: ‘lgs_rdescription’}],
url: ‘admin/lgroups_actions.php’,
cache: false,
autoBind: false,
addrow: function (rowid, rowdata, position, commit) {console.log(‘Add rowid in grid for ‘ + rowid); commit(true);}
};When i click the add button a window opens to insert the values i want in the new row then i add it to the grid as:
$(‘#addWindow’).on(‘close’, function (event) {
if (event.args.dialogResult.OK) {
var datarow = generaterow();
var commit = $(‘#adm_sitesgrid’).jqxGrid(‘addrow’, null, datarow);
}
});As i do this i see in the browser console the indication a new rowid has been created as i have a console log in the source addrow callback function.
When i try to delete i have the following code:
$(“#lgs_button_delete”).on(‘click’, function () {
var selected = $(“#adm_sitesgrid”).jqxGrid(‘getselectedrowindex’);
alert(selected);
var row = ds_lgroupssites.records[$(“#adm_sitesgrid”).jqxGrid(‘getrowid’, selected)];
alert(JSON.stringify(row));
$(‘#confirmboxcontent’).html(“<p align=’center’><br/>Are you sure you want to delete this item?</p>”);
$(‘#deleteWindow’).jqxWindow(‘open’);
});when i run this the first “selected” var is shown (with the selectedindex) but “row” var (from the rowid selection) does not return anything.
The strange of this is that if a initialize the grid with at least one valur (row) from the DB, i can add/delete rows without any problems.
Would you have any idea why this is happening?
Please let me know if you need further details.
Thanks you very much for your help,
Regards,
Carlos CastroHi Carlos,
I don’t know what is: ds_lgroupssites.records, but if you want to get a row in jqxGrid, then you should use its “getrowdata” method. To get all rows in jqxGrid, you should use the “getrows” method.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.