jQWidgets Forums
jQuery UI Widgets › Forums › Plugins › Data Adapter › Select dataAdapter record based on outside variable
Tagged: condition, dataadapter, filter loaded records, jqxDataAdapter, record, select variable, server side filtering, variable, WHERE
This topic contains 1 reply, has 2 voices, and was last updated by Dimitar 9 years, 9 months ago.
-
Author
-
Is it possible for dataAdapter to return a record (and a specific field value from within that record) based on a variable outside dataAdapter?
For instance:var outside = somevalue; var source = { datatype: "json", datafields: [ { name: 'shortname'}, { name: 'longname'} ], url: 'databasearray.php'}; var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function (records) { var records = dataAdapter.records;
// i would then like to select the specific record row where datafield ‘longname’ = outside.
// from this identified row, i would like the function to return the value of ‘shortname’.
// can I achieve that dynamic row selection based on the “var outside” from within dataAdapter?
// many thanks, –Jason... }, loadError: function (jqXHR, status, error) { }, beforeLoadComplete: function (records) { } }); dataAdapter.dataBind();
Hello Jason,
There are two possible ways to achieve this:
- Server-side – load only the necessary record(s) by sending the value of outside to the server and returning database records depending on it (with the WHERE clause). You can pass the value with the source object’s data property, i.e.:
var outside = somevalue; var source = { datatype: "json", datafields: [{ name: 'shortname' }, { name: 'longname' }], url: 'databasearray.php', data: { outside: outside } }; var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function(records) { var records = dataAdapter.records; }, loadError: function(jqXHR, status, error) {}, beforeLoadComplete: function(records) {} }); dataAdapter.dataBind();
- Client-side – filter the loaded records in beforeLoadComplete:
var outside = somevalue; var source = { datatype: "json", datafields: [{ name: 'shortname' }, { name: 'longname' }], url: 'databasearray.php' }; var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function(records) { var records = dataAdapter.records; }, loadError: function(jqXHR, status, error) {}, beforeLoadComplete: function(records) { var filteredRecords = []; for (var i = 0; i < records.length; i++) { if (records[i].longname === outside) { filteredRecords.push(records[i]); } } return filteredRecords; } }); dataAdapter.dataBind();
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ - Server-side – load only the necessary record(s) by sending the value of outside to the server and returning database records depending on it (with the WHERE clause). You can pass the value with the source object’s data property, i.e.:
-
AuthorPosts
You must be logged in to reply to this topic.