I have a grid store with something like this.
var gridStore = Ext.create('Ext.data.Store',{
proxy : {
type : 'ajax',
actionMethods : {
read : 'POST'
},
url : 'getECIAgentWrapperJobs.do',
reader : {
type : 'json',
rootProperty : 'rows',
totalProperty : 'results'
}
},
pageSize : 3,
autoLoad : {start: 0, limit: 3}
});
Clearly it makes an AJAX request to the url.
The JSON response that I am getting for this store looks something like this :
{
"results":2,
"rows":[
{
"pkTable1":1,
"name":"Rick",
"eciAgentJob":{
"pkTable2":11,
"name":"Play Local Ar",
},
}
],
"msg":null,
"success":true,
}
Now this is how my grid looks :
var mappedEciAgentJobsGrids = Ext.create('Ext.grid.Panel',{
store : gridStore,
columns : [
{
dataIndex : 'pkTable1',
header : 'Pk of table 1'
},
{
dataIndex : 'name',
header : 'Name'
},
{
dataIndex : 'eciAgentJob.pkTable2',
header : 'Pk of Table 2'
}
]
});
Now in my UI the first 2 columns(with dataIndex: pkTable2 and name respectively) load fine. But for the 3rd one it does not.
I know it is because I have used dataIndex as 'eciAgentJob.pkTable2'. But then what is that way to load data in columns when we get response like the way I got(where eciAgentJob is a object inside the original JSON).
Please help.
Edit : I dont want to use a renderer due to some other use case reasons.
Define a new field in your model and map with the required field. In convert function pick any value from the record.
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string ' },
{
name: 'columnName',
convert: function (value, record) {
return "return what ever you want"
}
}
]
});
Related
I created function which is adding people_id inside array of given card. But there is problem that inserted id is always not as an objectId() where I just need it to be saved as objectId.
When id is added to array i I'm sending whole variable board JSON to nodejs API where is executed function findOneAndUpdate. And here is problem because after saved this arrays is not objectID in Author. Can someone tell me how to make it?
JSON board
{
"_id" : ObjectId("59e096a7622a3825ac24f343"),
"name" : "1",
"users" : [
ObjectId("59cd114cea98d9326ca1c421")
],
"lists" : [
{
"list" : "1",
"cards" : [
{
"name" : "2",
"Author" : [
"59df60fb6fad6224f4f9f22d",
"59df60fb6fad6224f4f9f22d",
"59df60fb6fad6224f4f9f22e"
]
},
{
"name" : "3",
"Author" : []
}
]
},
{
"list" : "fea",
"cards" : [
{
"name" : "card",
"Author" : []
}
]
}
],
"__v" : 0 }
Router:
router.post('/add/member', function (req, res, next) {
console.log(req.body)
Board.findOneAndUpdate({ _id: req.body._id },
{
$set: {
lists : req.body.lists
}
},
{
upsert: true
},
((cards) => {
res.send(cards)
})
)
});
model:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var BoardSchema = new Schema({
name: { type: String, maxlength: 20 },
lists : { type: Array },
users : [{ type : Schema.Types.ObjectId, ref: 'User' }],
});
module.exports = mongoose.model('Board', BoardSchema);
And here is function with adding poeple
$scope.addMemberToCard = (indexList, indexCard, member) => {
$scope.board.lists[indexList].cards[indexCard].Author.push(member);
console.log( $scope.board.lists[indexList].cards[indexCard].Author)
return ApiService.staff.addMemberToCard($scope.board).then(function () {
})
}
You could use the mongoose Types ObjectID method and then transform the string sent into an ObjectID.
const id = new new mongoose.Types.ObjectId(Author);
I have successfully set up several KendoUI Grids, but I cannot get one using server-side paging to work.
I modified my rest service so I will return a total value (hard coded right now).
I also modified my javascript source. [see below].
Usually I just get a blank screen.
Would be very grateful for any assistance.
Script:
$(document).ready(function(){
// Setup Rest Service
var loc = ( location.href );
var url = loc.substring( 0, loc.lastIndexOf( "/" ) ) + "/xpRest.xsp/test/";
dataSource = new kendo.data.DataSource({
pageSize: 20,
serverPaging: true,
serverFiltering: true,
serverSorting: true, transport : {
read : {
url : url + "READ",
dataType : "json"
},
type : "READ"
},
schema : {
total: "total",
model : {
id : "unid",
fields : {
unid : {
type : "string",
nullable : false
},
tckNbr : {
type : "string",
editable : false
},
tckSts : {
type : "string",
editable : false
}
}
}
}
});
grid = $("#grid-databound-dataItem").kendoGrid({
dataSource : dataSource,
height: 550,
filterable: true,
sortable: true,
pageable: true,
columns : [
{field : "tckNbr", title : "Number", type: "string"},
{field : "tckSts", title : "Status", type: "string"}
]
}).data("kendoGrid");
});
JSON feed:
[
{
"total":100,
"data":
[
{
"tckNbr":"3031",
"tckSts":"1 Not Assigned",
"unid":"0014DA9095BF6D638625810700597A36",
"tckReqs":"Bryan S Schmiedeler",
"tckNts":
[
"Bryan DeBaun"
],
"tckBUs":
[
"NAP\/IFI"
],
"tckApps":"GTM",
"tckType":"Issue",
"tckPriority":"Medium"
},
{
"tckNbr":"3031",
"tckSts":"1 Not Assigned",
"unid":"00598976D88226D2862581070059AD25",
"tckReqs":"Bryan S Schmiedeler",
"tckNts":
[
"Bryan DeBaun"
],
"tckBUs":
[
"NAP\/IFI"
],
"tckApps":"GTM",
"tckType":"Issue",
"tckPriority":"Medium"
}
]
}
]
Correct your JSON feed, you need to return object not array:
{
"total": 10,
"data": []
}
After that say what is data and what is total in you schema:
schema : {
total: "total",
data: "data",
.
.
}
Note: if you mock data like in your case (total: 100, data -> size is 2) your paginatio will be created by total parameter not data itself. You will see 5 pages with same data (that is ok).
I'm stucked into a problem that I need to pass my schema and my json to my constructor. First of all, I'm using Reactabular to develop a SPA, but in this library I can only start the application using a function that they have created called generateRows, but I have my own objects to inject, so I don't want to generate rows.
In my component i have this chunk of code:
class AllFeaturesTable extends React.Component {
constructor(props) {
super(props);
this.state = {
rows: generateRows(5, schema),
searchColumn: 'all',
query: {}, // search query
sortingColumns: null,
columns: this.getColumns(),
pagination: {
page: 1,
perPage: 5
}
};
When I pass my rows as json object array everything works great untill I try to edit these values, and makes sense why i cannot edit this data. I can't because i didn't passed the schema(as you guys can see in the generaterows they took as parameter the schema).
My question is how can I achieve this? pass in my this.state.row the schema and my rows.
This is my rows:
const predefinedRows = [
{ "combustivel" : "Flex",
"imagem" : null,
"marca" : "Volkswagem",
"modelo" : "Gol",
"placa" : "FFF-5498",
"valor" : 20000
},
{ "combustivel" : "Gasolina",
"imagem" : null,
"marca" : "Volkswagem",
"modelo" : "Fox",
"placa" : "FOX-4125",
"valor" : "20000"
},
{ "combustivel" : "Alcool",
"imagem" : "http://carros.ig.com.br/fotos/2010/290_193/Fusca2_290_193.jpg",
"marca" : "Volkswagen",
"modelo" : "Fusca",
"placa" : "PAI-4121",
"valor" : "20000"
}
];
and this my schema :
const schema = {
type: 'object',
properties: {
combustivel: {
type: 'string'
},
imagem: {
type: 'string'
},
marca: {
type: 'string'
},
modelo: {
type: 'string'
},
placa: {
type: 'string'
},
valor: {
type: 'integer'
}
},
required: ['combustivel', 'imagem', 'marca', 'modelo', 'placa']
};
Thanks in advance!
You should not use generateRows. generateRows introduced here, just return a dummy array data.
Just follow the example to implement your component.
If you want to use all features, and pass to this.state.row the schema and rows. Just do this:
this.state = {
row: {
rows: yourRows,
schema: yourSchema
},
searchColumn: 'all',
query: {}, // search query
sortingColumns: null,
columns: this.getColumns(),
pagination: {
page: 1,
perPage: 5
}
};
I have JSON with structure like this:
"id":1,
"user_role":"ADMIN",
"state":"ACTIVE",
"address":{
"street":"test 59",
"city":"City test",
"post_number":"25050"
},
How I should to pass values of address.street into column using setting in fields and model?
Many thanks for any advice.
If you want to show all values in a single column do what #RobinGiltner suggests.
If you want to show each member of address in a different column you can do:
var grid = $("#grid").kendoGrid({
dataSource: data,
editable: true,
columns : [
{ field: "id", title: "#" },
{ field: "user_role", title: "Role" },
{ field: "address.street", title: "Street" },
{ field: "address.city", title: "City" },
{ field: "address.post_number", title: "Post#" }
]
}).data("kendoGrid");
i.e.: use address.street as name of the field. This would allow you even to edit the field as in the example: http://jsfiddle.net/OnaBai/L6LwW/
#OnaBai Good and intuitive answer. Sadly Kendo doesn't always work to well with nested properties this way. For example formating doesn't work. Here is an example using data source shema to access nested properties. This way you can use formatting but you have to specify a schema model.
var grid = $("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
id: "id",
fields: {
id: { type: "number" },
user_role: { type: "string" },
address_street: { from: "address.street" },
address_city: { from: "address.city" },
address_post_number: {
type: "number",
from: "address.post_number"
}
}
}
}
},
columns: [{
field: "id",
title: "#"
}, {
field: "user_role",
title: "Role"
}, {
field: "address_street",
title: "Street"
}, {
field: "address_city",
title: "City"
}, {
field: "address_post_number",
title: "Post#",
format: "{0:0#######}"
}]
}).data("kendoGrid");
Jsfiddle: http://jsfiddle.net/wtj6mtz2
See also this Telerik example for accessing nested properties.
You could use a template on the grid column definition to display whichever pieces of the address you wanted.
{ field: 'address', title: 'Address', template: '#= address.street# #= address.city#, #= address.post_number# ' },
See documentation for kendo column template. http://docs.telerik.com/kendo-ui/api/web/grid#configuration-columns.template
See sample at http://jsbin.com/gizab/1/edit
i have a json in the following format:
{
"collection": [
{
"id": 4,
"tickets": {
"collection": [
{
"inner_id": 8,
},
{
"inner_id": 10,
}
],
"count": 2,
"type": "collection"
},
},
{
"id": 5,
"tickets": {
"collection": [
{
"inner_id": 1,
},
{
"inner_id": 2,
}
],
"count": 2,
"type": "collection"
},
},
]
}
For this particular JSON i created the models as:
Ext.define("myProject.model.ABC", {
extend: "Ext.data.Model",
config: {
idProperty: "id",
fields:[
{name: "id", type: "int" },
],
hasMany: [
{
model: "myProject.model.XYZ",
name: "tickets",
associationKey: "tickets",
},
],
}
});
And second store as:
Ext.define("myProject.model.XYZ", {
extend: "Ext.data.Model",
config: {
// idProperty: "id",
fields:[
{name: "inner_id", type: "int" },
],
belongsTo: 'myProject.model.ABC'
}
});
But now i am confused. How do i populate the second store with a root property of collection again.
I know one way is to easily change the json so that there is no collection child inside tickets but i dont want to do that.
Any help would be appreciated. I have simplified the JSON for an easy example.
EDIT:
To be more clear, is there a way i can directly create a model which will read the Collection array inside the tickets object.
EDIT:
Adding the store which populates the model ABC for more understanding
Ext.define("myProject.store.ABCs", {
extend: "Ext.data.Store",
config: {
model: "myProject.model.ABC",
autoLoad: false,
proxy: {
type: "ajax",
url: '', //myURL
reader: {
type: "json",
rootProperty: "collection", // this is the first collection
},
},
}
});
This store loads the ABC model correctly but now i want to load the XYZ model which can load the inner array of collection
belongsTo should be define as follows :
Ext.define('Product', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'category_id', type: 'int' },
{ name: 'name', type: 'string' }
],
associations: [
{ type: 'belongsTo', model: 'Category' }
]
Have you read the doc? They specified the root property.
The name of the property which contains the data items corresponding to the Model(s) for which this Reader is configured. For JSON reader it's a property name (or a dot-separated list of property names if the root is nested). For XML reader it's a CSS selector. For Array reader the root is not applicable since the data is assumed to be a single-level array of arrays.
By default the natural root of the data will be used: the root JSON array, the root XML element, or the array.
The data packet value for this property should be an empty array to clear the data or show no data.
Sometimes the JSON structure is even more complicated. Document databases like CouchDB often provide metadata around each record inside a nested structure like this:
{
"total": 122,
"offset": 0,
"users": [
{
"id": "ed-spencer-1",
"value": 1,
"user": {
"id": 1,
"name": "Ed Spencer",
"email": "ed#sencha.com"
}
}
]
}
In the case above the record data is nested an additional level inside the "users" array as each "user" item has additional metadata surrounding it ('id' and 'value' in this case). To parse data out of each "user" item in the JSON above we need to specify the record configuration like this:
reader: {
type : 'json',
root : 'users',
record: 'user'
}
root as a Function
reader: {
type : 'json',
root : function (obj) {
// I can't reproduce your problem
// so you should check in your console collection.id is right
return obj.collection.id
}
}
// Or, we can use dot notation
reader: {
type : 'json',
root : collection[0].tickets.collection
}
There are two ways to solve this problem. After researching extensively, i found two solutions...
SOLUTION 1:
Instead of making a second model, just create one model and create an array field with type as "auto"
Ext.define("myProject.model.ABC", {
extend: "Ext.data.Model",
config: {
idProperty: "id",
fields:[
{name: "id", type: "int" },
{ name: "tickets", convert: function(value, record) {
if(value.collection instanceof Array) {
return value.collection;
} else {
return [value.collection]; // Convert to an Array
}
return value.collection;
}
}
],
}
});
Now you can refer to an array of tickets from records by:
record.get('tickets')
SOLUTION 2:
Create three model instead of two.
Model 1:
hasOne Association with Tickets
Model 2:
hasMany association with Collection
Model 3:
has all the fields of the innermost array
I can give an example if its not clear enough