dataSource.data() doesn't return the datas - kendo-ui

I'm currently testing kendoUI and developping a little webapp.
For some reason I need to pass my dataSource.datas from a view to another. In order to do this I use sessionStorage and when I try to put my dataSource.data() in sessionStorage, the return is empty.
See here when I put a log to test if my dataSource.data() is correctly inserted/returned
However, when I put a log to test ma dataSource I can clearly see that _data is not empty as it is showed in the follow picture :
Did someone know the origin of my problem ?
EDIT
here is the code that shows how I add my dataSource to sessionStorage :
var qui = (e.view.params.qui) ? e.view.params.qui : "";
var quoi = (e.view.params.quoi) ? e.view.params.quoi : "";
dataSourceFournisseurs = new kendo.data.DataSource({
transport : {
read : {
url:"annuaire.json",
dataType:"json"
}
},
schema : {
data : "data",
model : {
DISTANCE: function() {
var lat = this.get("LATITUDE");
var lng = this.get("LONGITUDE");
var distance = APP.distanceBetweenCoords(lat, lng);
return "à " + distance + "km";
}
}
},
sort : {
field : "LIBELLE",
dir : "asc"
},
filter: [
{ field: "LIBELLE", operator: "contains", value: qui },
{ field: "NAFLIBELLE", operator: "contains", value: quoi }
]
});
console.log(dataSourceFournisseurs);
session.setValueObject("liste", dataSourceFournisseurs.data());
And here is how I retrieve it :
var datas = session.getValueObject("liste");
console.log(datas);
PS :
setValueObject and getValueObject are two methods I wrote in order to Stringify the datas I set and Parse the retrieved datas (there are fully functionnal I use them for over a year)
the two console.log are those that represent the picture above (picture 1 with second log and picture 2 with first log)
EDIT END

Try using dataSourceFournisseurs.view(). This should give you the all of the data. Using data is meant for initial configuration, and is not meant to be used as a method for retrieving data.
Bonne chance!

Related

Spring - How to correctly show relationship data in view (table) using REST api

I have a User (id, username) entity which has many-to-many relationship with Roles (id, name) entity. I am trying to show the User data in a ajax Datatable. Now, if a User has six roles, it shows six [object Object] for all six roles. I dont know how to correctly show the role name instead of object Object.
This is what I have:
.DataTable(
{
"pagingType" : "full_numbers",
"sAjaxSource" : "/api/AppUser/all",
"sAjaxDataProp" : "",
"aoColumns" : [
{
"data" : "id"
},
{
"data" : "username"
},
{
"data" : "userenabled"
},
{
"data" : "useremail"
},
{
"data" : "userfirstname"
},
{
"data" : "userlastname"
},
{
"data" : "useraddress"
},
{
"data" : "roles"
}
This is how it looks like in Data Table:
Here is my REST Controller piece:
#RestController
#RequestMapping("/api/AppUser")
public class AppUserRestAPIs {
#GetMapping(value = "/all", produces = "application/json")
public List<AppUser> getResource() {
return appUserJPARepository.findAll();
}
}
I know it must be trivial but feeling lost and could not find a single example on how to represent relationship data in view (html) using REST api. Searched almost everywhere. What I am missing here? Will appreciate any pointers here.
Answering my own question:
Found it ! Here - https://editor.datatables.net/examples/advanced/joinArray.html
So instead of:
{
"data" : "roles"
}
I have to use:
{
"data" : "roles",
render : "[, ].name"
}
All worked perfectly but now I am clueless what if I don't use Datatable. Not sure if I have to put another question for it.
Use function to flat roles list:
Instead of
{
"data" : "roles"
}
Try this :
{
"data": null,
"render": function(data, type, row, meta) {
var flatrole = '';
//loop through all the roles to build output string
for (var role in data.roles) {
flatrole = flatrole + role.name + " ";
}
return flatrole;
}
}

how to use mongodb query option in monk nodejs

I have a collection name projects and I am trying to retrieve everything except its url like this query
db.projects.find({name:"arisha"},{url:0}).pretty()
This query is working perfectly and returning everything except url but my question is how to achieve this in
Node module for MongoDB name monk.
I am using this code but its not working and returning every field:
var projs = db.get('projects');
projs.find({creator : req.session.user._id},{url:0}, function (err,data) {
console.log(data);
if(!err) {
res.locals.projs = data;
console.log(data);
res.render("projects.ejs",{title: "Projects | Bridge"});
}
});
I did not get where the problem is, please help and thanks in advance :)
Sample document:
{
"name" : "arisha",
"date" : {
"day" : 18,
"month" : 4,
"year" : 2015
},
"creator" : "552edb6f8617322203701ad1",
"url" : "EyjPdYoW",
"members" : [
"552edb6f8617322203701ad1"
],
"_id" : ObjectId("5532994ba8ffdca31258bd1a")
}
To exclude the url field in monk, try the following syntax:
var db = require('monk')('localhost/mydb');
var projs = db.get('projects');
projs.find({ creator : req.session.user._id }, "-url", function (err, data) {
// exclude url field
});
EDIT:
To exclude multiple fields, use the following projection syntax:
projs.find({ creator : req.session.user._id }, { fields: { url: 0, creator: 0 } }, function(err, data) {
// exclude the fields url and creator
});
Alternatively (as you had discovered), you could also do:
projs.find({ creator : req.session.user._id }, "-url -creator", function (err, data) {
// exclude url and creator fields
});

Parse.com manipulate Response Object

I am trying to work Ember with Parse.com using
ember-model-parse-adapter by samharnack.
I add added a function to make multiple work search(like search engine) for which I have defined a function on cloud using Parse.Cloud.define and run from client.
The problem is the Array that my cloud response returns is not compatible with Ember Model because of two attributes they are __type and className. how can I modify the response to get response similar to that i get when I run a find query from client. i.e without __type and className
Example responses
for App.List.find() = {
"results":[
{
"text":"zzz",
"words":[
"zzz"
],
"createdAt":"2013-06-25T16:19:04.120Z",
"updatedAt":"2013-06-25T16:19:04.120Z",
"objectId":"L1X55krC8x"
}
]
}
for App.List.cloudFunction("sliptSearch",{"text" : this.get("searchText")})
{
"results":[
{
"text":"zzz",
"words":[
"zzz"
],
"createdAt":"2013-06-25T16:19:04.120Z",
"updatedAt":"2013-06-25T16:19:04.120Z",
"objectId":"L1X55krC8x",
"__type" : Object, //undesired
"className" : "Lists" //undesired
}
]
}
Thanks Vlad something like this worked for me for array
resultobj = [];
searchListQuery.find({
success: function(results) {
for( var i=0, l=results.length; i<l; i++ ) {
temp = results.pop();
resultobj.push({
text: temp.get("text"),
createdAt: temp.createdAt,
updatedAt: temp.updatedAt,
objectId: temp.id,
words: "",
hashtags: ""
});
}
In your cloud code before you make any response, create and object and extract from it the attributes/members you need and then response it. like so:
//lets say result is some Parse.User or any other Parse.Object
function(result)
{
var responseObj = {};
responseObj.name = responseObj.get("name");
responseObj.age = responseObj.get("age");
responseObj.id = responseObj.id;
response.success(responseObj);
}
on the response side you will get {"result": {"name": "jhon", "age": "26", "id": "zxc123s21"}}
Hope this would help you

YUI3 datatable not rendering data when using Plugin.DataTableDataSource with JSON

I've been trying, unsuccessfully, to get a yui3 datatable to correctly populate via a json call. I am flummoxed and hope someone can show me the error of my ways. No matter what I have tried I just get "No data to display".
When I run wireshark during the page load I am seeing the json data returned from the ajax call. So I think I have the data source bound to the data table correctly. Note that the data records I am interested in are nested with metadata and it appears my DataSourceJSONSchema definition is correct.
Here is the http response from the ajax call.
YUI.Env.DataSource.callbacks.yui_3_6_0_1_1346868215546_114({
"recordsReturned":4,"startIndex":0,"dir":"asc","pageSize":10,
"records":[
{"id":"48ee0540-ebd7-11e1-33e-c33ce39c9e", "email":"jim#example.com","name":"James"},
{"id":"1447ea60-eca2-11e1-33e-f6c33ce39c9e", "email":"john#example.com","name":"John"},
{"id":"48ff6a60-ebd7-11e1-a33e-f6c33ce39c9e", "email":"ryan#example.com","name":"Ryan"},
{"id":"1a298060-f774-11e1-ad38-f6c33ce39c9e", "email":"vincent#example.com","name":"Vince"}]})
Here is the html page.
<script type="text/javascript">
YUI({
lang : "en-US"
})
.use("datatable","datatype","datasource",function(Y) {
var ajaxData;
function ajaxSuccess(e) {
ajaxData = e.data;
}
}
function ajaxFailure(e) {
Y.log("failure");
}
var myDataSource = new Y.DataSource.Get({
source : "/actions/User.action?getAjaxUserList=&"
});
myDataSource.plug(Y.Plugin.DataSourceJSONSchema,{
schema : {
metaFields : {
recordsReturned : "recordsReturned",
startIndex : "startIndex",
dir : "dir",
pageSize : "pageSize"
},
resultsListLocator : "records",
resultFields : [ {
key : 'id'}, {
key : 'email'},{
key : 'name' }}});
var table = new Y.DataTable({
columns : [ {
key : "id",
label : "ID"
}, {
key : "name",
label : "Name"}, {
key : "email",
label : "Email"} ],
caption : "My first DataTable!",
summary : "Example DataTable showing basic instantiation configuration"
});
table.plug(Y.Plugin.DataTableDataSource, {datasource : myDataSource});
table.render('#dynamicdata');
table.datasource.load({request : encodeURIComponent('fred=steve')});
});
</script>
<div id="dynamicdata"></div>
I noticed several syntax error on the code you give here :
The function(Y) callback is closed too soon for example.
I think your error is due to the fact that you set in the schema of your Datasource the property "resultsListLocator" instead of "resultListLocator".

YUI DataTable Loading...but no data retrieved

I have a YUI datatable bound to a YUI datasource that needs to be auto-refreshed after a couple of seconds and also manually through a button. While I am able to read the data through a local datasource (datasource declared in the same page) I am not able to read it remotely. The grid remains "Data Loading..." even though the requests to the target page (yui_data.cfm) are being made at the set interval. The source code is the following:
Source code of yui_data.cfm (for testing) is the following:
{ "records": [ {"id": 31, "name":"4fruit", "price":8323, "number":231} ] }
Source code of the page requesting the data:
myDataSource = new YAHOO.util.XHRDataSource("yui_data.cfm?");
myDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
myDataSource.responseSchema = {
resultsList: "records",
fields: [
{key:"id", parser:"number"},
{key:"name"},
{key:"price",parser:"number"},
{key:"number",parser:"number"}
]
};
myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, myDataSource);
myCallBack = {
success: myDataTable.onDataReturnSetRows,
failure: function() {
},
scope: myDataTable,
argument: myDataTable.getState()
}
myDataSource.setInterval(5000, null, myCallBack);
The above example only works when the line
myDataSource = new YAHOO.util.XHRDataSource("yui_data.cfm?");
is changed to:
myDataSource = new YAHOO.util.XHRDataSource(YAHOO.data.sample); // as an example!
I managed to fix the problem by preceding the previous JSON output with a ResultSet and Result and then modifying the response schema resultList to read from that path.

Resources