jQuery UI Widgets › Forums › Plugins › Data Adapter › Getting value from dataAdapter
Tagged: data adapter, dataadapter, jqxDataAdapter, loadComplete, records
This topic contains 9 replies, has 6 voices, and was last updated by otonksaz 9 years, 6 months ago.
-
Author
-
Hi,
I’m using dataAdapter to dynamic bind source with ajax call (I have 3 columns: id, value, type). How can I get type column for the first row of datadapter?
Did something like this:
var source={ datatype: "json", datafields: [ { name: 'id', type: 'string' }, { name: 'value', type: 'string' }, { name: 'type', type: 'string' } ], url: "client/get_data.jsp", data: { operation: '3' } }; var sDataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function() { var record_array = sectionDataAdapter.records; alert(record_array.length > 0 ? ((record_array[0].type != null && record_array[0].type.trim.length > 0) ? record_array[0].type : "type is null") : ""); } });
But it always shows “type is null”.
I solved it, thank you 🙂
Excuse me, but how did you solved it?
Hello eabarca,
As far as I can see, in loadComplete sectionDataAdapter.records has to be changed to sDataAdapter.records.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks, i got it work as i need. Adapter has 7 fields and it feeds combobox, when i change item i get the fields from adapter. If anyone needs an example let me know and i post here.
Hello,
I am having problems determining how to get values from my dataAdapter.
function getSingleNewsItem(id) { var url = '@Url.Action("AjaxGetSingleNewsItem", "News")'; var source = { datatype: "json", dataFields: [ { name: 'Id', type: 'string' }, { name: 'NewsItemImageReference', type: 'string' }, { name: 'ImagePath', type: 'string' }, { name: 'Title', type: 'string' }, { name: 'SubTitle', type: 'string' }, { name: 'AddedOn', type: 'date' }, { name: 'NewsRef', type: 'string' }, { name: 'BodyText', type: 'string' } ], id: id, data: { id: id }, url: url }; var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function (record) { var container = "<div style=\" padding-left:10px; padding-right:10px;\">" + "<div style=\" width: 100%; \">" //+ "<img style=\"width: 600px; height: 500px; padding: 10px;\" alt=\"\" src=\"" + data.NewsItemImageReference + "\"></img>" + "</div>" + "</br>" + "<div style=\" width: 100%; \">" + "Ref: " + record.NewsRef + "</br>" + record.BodyText + "</div>" + "</div>"; $("#newsDetailsTable").html(container); $('#jqxwindow-news').jqxWindow('open'); } }); // perform data binding. dataAdapter.dataBind(); }
This is my JSON:
[ { "ImagePath": "http://vmwebapps.rhs.net/AMT/AMT_Files/HortifactsAttachmentsTest/NewsItems/", "Id": "6", "NewsItemImageReference": "http://vmwebapps.rhs.net/AMT/AMT_Files/HortifactsAttachmentsTest/NewsItems/9750cf57-bc14-4205-9e6c-83c8406f3f82.jpg", "Title": "Tree fungus ID", "SubTitle": " Inonotus dryadeus", "AddedOn": "16/09/2013", "NewsRef": "204201/252874", "BodyText": "Ref: 204201/252874The fruiting bodies are those of a fungus called Inonotus dryadeus. Oak is the most common host of this fungus, which can often cause decay of the inner parts of the root system and the base of the trunk.Whilst the fungus can cause extensive decay, the effect on the tree itself can be very variable. Some trees will survive for many years or even indefinitely - although the central roots and wood may decay the hollow tree remains alive and standing on 'stilts' of buttress roots. However, if the decay also affects these roots then there is a risk of the tree falling. In a case such as this we would always recommend having the tree examined in situ by an arboricultural consultant, particularly if there is any risk of injury or damage to property should the tree fall. The consultant will be able to check the location and extent of the decay, and recommend any appropriate remedial action (such as crown reduction).The link below takes you to our web profile on bracket fungi. This does not mention Inonotus dryadeus specifically, but gives the contact details for the Arboricultural Association who will be able to provide you with a list of suitably-qualified consultants operating in your area. http://apps.rhs.org.uk/advicesearch/Profile.aspx?pid=98I hope this information is helpful.Yours sincerely, John ScracePlant Pathologist" } ]
Hi nickgowdy,
The problem in the provided code is that you don’t take into account the fact that the parameter in the loadComplete is Array. You take this as an Object, but its actually “records”, not “record” and to access first record, you should write records[0].
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hello Peter,
I’ve tried your suggestion, I renamed the parameter of loadComplete to “records” and I’ve tried to access it with the array index. This is my console.log.
`console.log(records);
console.log(records[5]);`[{"ImagePath":"http://vmwebapps.rhs.net/AMT/AMT_Files/HortifactsAttachmentsTest/NewsItems/","Id":"12","NewsItemImageReference":"http://vmwebapps.rhs.net/AMT/AMT_Files/HortifactsAttachmentsTest/NewsItems/7bc9ca37-d3da-4972-9f19-be3f245eb905.jpg","Title":"Large Yellow U","SubTitle":"derwing","AddedOn":"25/09/2013","NewsRef":" yellow under","BodyText":"Large yellow underwing - sent via twitter - Anna says several already submitted to our entomologists this week: https://twitter.com/HannahBellaaaa/status/382814806886973440/photo/1Massed eggs diagnostic: http://ukmoths.org.uk/show.php?bf=2107"}] (index):481 a
As you can see, by supplying an int for records, it’s getting the character of the JSON string. Maybe this is a basic question but I don’t understand how to use the dataAdapter data to build my HTML.
I’ve used a jQuery.ajax success function in the past and could access the data through the parameter of the success function.
Hi nickgowdy,
Ok, to learn how to use this plugin, it would be best to look at its help topic: http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdataadapter/jquery-data-adapter.htm
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Eabarca,
I have some problem like you.
I have adapter with multiple fields and it feeds to combobox on grid.
I need to get all fields value when I select this combobox.
how can I do that?
can you give me example?sorry my english is bad.
Best Regards,
Otonksaz -
AuthorPosts
You must be logged in to reply to this topic.