jQuery UI Widgets › Forums › Lists › ListBox › Listbox refresh duplicating
Tagged: duplicate, jqxListBox, refresh
This topic contains 2 replies, has 2 voices, and was last updated by dutoitco 7 years, 7 months ago.
-
Author
-
I’ve got a list box using json data from a php script. When I select an item, it fills an adjacent form, which, after editing, saves the updates to a database using $.post(). On successfully updating the database, I’m using
$("#jqxlistbox").jqxListBox('refresh');
to update the list, but instead of updating it is showing the list data twice – the original list, and then the list with the edited item. Here’s the relevant code:var source = { url: 'getEmployees.php', datatype: "json", datafields: [ { name: 'employeesID', type: 'int' }, { name: 'clockId', type: 'int' }, { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' } ], id: 'clockId' }; var dataAdapter = new $.jqx.dataAdapter(source, { beforeLoadComplete: function (records) { // update the loaded records. for (var i = 0; i < records.length; i++) { var employee = records[i]; employee.name = employee.firstname + " " + employee.lastname; data.push(employee); } return data; } }); // Create a jqxListBox $("#jqxlistbox").jqxListBox({source: dataAdapter, displayMember: "name", valueMember: "employeesID", width: '98%', height: '88%', filterable: true }); // bind to 'select' event. $('#jqxlistbox').bind('select', function (event) { var args = event.args; var item = $('#jqxlistbox').jqxListBox('getItem', args.index); $('#empID').val(data[item.index].employeesID); $('#firstname').val(data[item.index].firstname); $('#lastname').val(data[item.index].lastname); }); $.post('includes/saveEmployee.php', {'employeesID': $('#empID').val(), 'firstname': $('#firstname').val(), 'lastname':$('#lastname').val()}, function(data){ if (isNaN(data)){ alert(data); } else { $("#jqxlistbox").jqxListBox('refresh'); } });
Any ideas?
Hi dutoitco,
Probably the problem is in your data variable.
It looks to be global and everytime when you update your list the new content is added instead to be updated.Best Regards,
Ivailo IvanovjQWidgets Team
http://www.jqwidgets.comAah duh! bloody stupid of me. Thanks though! (I left it global as I use the same data elsewhere, and just cleared the array before adding the new data. Works perfectly now.)
-
AuthorPosts
You must be logged in to reply to this topic.