Could any one help me how could I bind data object with DevExtreme's dxDataGrid using customstore.
My DTO is like:
[
data: {...},
totalCount: 100,
summary: [10,20,30]
]
But when i bind the data with dxDataGrid it just bind data but not totalCount.
I have found a solution for my problem.
[remoteOperations]="true"
I need remoteOperations = true to bind the totalCount along with data fetched from the server.
You don't need to send a totalCount, you have to use the summary section istead, look at this sample
$("#gridContainer").dxDataGrid({
dataSource: orders,
keyExpr: "ID",
showBorders: true,
selection: {
mode: "single"
},
columns: [{
dataField: "OrderNumber",
width: 130,
caption: "Invoice Number"
}, {
dataField: "OrderDate",
dataType: "date",
width: 160
},
"Employee", {
caption: "City",
dataField: "CustomerStoreCity"
}, {
caption: "State",
dataField: "CustomerStoreState"
}, {
dataField: "SaleAmount",
alignment: "right",
format: "currency"
}
],
summary: {
totalItems: [{
column: "OrderNumber",
summaryType: "count"
}]
}
});
Data Source
var orders = [{
"ID" : 1,
"OrderNumber" : 35703,
"OrderDate" : "2014-04-10",
"SaleAmount" : 11800,
"Terms" : "15 Days",
"TotalAmount" : 12175,
"CustomerStoreState" : "California",
"CustomerStoreCity" : "Los Angeles",
"Employee" : "Harv Mudd"
}, {
"ID" : 4,
"OrderNumber" : 35711,
"OrderDate" : "2014-01-12",
"SaleAmount" : 16050,
"Terms" : "15 Days",
"TotalAmount" : 16550,
"CustomerStoreState" : "California",
"CustomerStoreCity" : "San Jose",
"Employee" : "Jim Packard"
}....
]
For custom summaries you can use this
summary: {
totalItems: [{
name: "SelectedRowsSummary",
showInColumn: "SaleAmount",
displayFormat: "Sum: {0}",
valueFormat: "currency",
summaryType: "custom"
}
],
calculateCustomSummary: function (options) {
if (options.name === "SelectedRowsSummary") {
if (options.summaryProcess === "start") {
options.totalValue = 0;
}
if (options.summaryProcess === "calculate") {
if (options.component.isRowSelected(options.value.ID)) {
options.totalValue = options.totalValue + options.value.SaleAmount;
}
}
}
}
}
In the section if (options.summaryProcess === "calculate") { you can put your custom calc logic, in this case your total count.
I have a collection with order headers and positions (as array) and I need an query which should give me:
quantity of customers
quantity of orders
summed up order value
all grouped by date and order type. I already got this covered by two queries (see below), but I want to have it in one.
The main problem to me is that I need to count the orders but with positions unwinded.
E.g.: Below would be a possible result of the combined query with the test data below:
/* 1 */
{
"_id" : {
"typ" : "WERBUNG",
"date" : "2017-07-08"
},
"orderQuantity" : 1.0,
"value" : 1000,
"customerQuantity" : 1
}
/* 2 */
{
"_id" : {
"typ" : "WERBUNG",
"date" : "2017-07-07"
},
"orderQuantity" : 2.0,
"value" : 100,
"customerQuantity" : 1
}
/* 3 */
{
"_id" : {
"typ" : "ANDERE",
"date" : "2017-07-08"
},
"orderQuantity" : 4.0,
"value" : 1500,
"customerQuantity" : 4
}
/* 4 */
{
"_id" : {
"typ" : "ANDERE",
"date" : "2017-07-07"
},
"orderQuantity" : 1.0,
"value" : 90,
"customerQuantity" : 1
}
... this would mean:
On 7-7 there where 3 orders (WERBUNG 2, ANDERE 1) for only 1 customer (WERBUNG 1, ANDERE 1 - will be counted twice here, bit this would be okay)
On 8-7 there where 5 orders (WERBUNG 1, ANDERE 4) for 5 customers (WERBUNG 4, ANDERE 1)
I have an idea that SortBy would help here, however we still use 3.2 - so no access to this stage (and some other usefull options as well...).
Cheers!
--
Some information which might help:
// Here are the sample orders:
/*1*/
{
"_id" : ObjectId("596075d5be8fc415341c7d43"),
"header" : {
"kundennummer" : "820130",
"auftragsdatum" : 0,
"bestellangaben" : "BLOCK1",
"information1" : "blocktest",
"erstellungsdatum" : 1499493785.25906,
"vorgabeauftragsnummer" : 87475000,
},
"ordertype" : "BLOCK1",
"customernnummer" : "820130",
"ordernumber" : 87475000,
"positions" : [
"artikelnummer" : 1985900,
"menge" : 1,
"bruttopreis" : 1000,
"_id" : ObjectId("596075d5be8fc415341c7d45")
}
],
"date" : "2017-07-08",
"type" : "WERBUNG"
}
/*2*/
{
"_id" : ObjectId("59608f64be8fc415341c7d46"),
"header" : {
"kundennummer" : "944867",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499500356.10022,
"vorgabeauftragsnummer" : 87475001,
},
"ordertype" : "",
"customernnummer" : "944867",
"ordernumber" : 87475001,
"positions" : [
{
"artikelnummer" : 4029300,
"menge" : 1,
"bruttopreis" : 100,
"_id" : ObjectId("59608f64be8fc415341c7d5c")
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*3*/
{
"_id" : ObjectId("5960925ebe8fc415341c7d5d"),
"header" : {
"kundennummer" : "981927",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499501036.34265,
"vorgabeauftragsnummer" : 87475002,
},
"ordertype" : "",
"customernnummer" : "981927",
"ordernumber" : 87475002,
"positions" : [
},
"artikelnummer" : 4557300,
"menge" : 2,
"bruttopreis" : 100,
"_id" : ObjectId("5960925ebe8fc415341c7d74")
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*4*/
{
"_id" : ObjectId("5960925ebe8fc415341c7d75"),
"header" : {
"kundennummer" : "981927",
"auftragsdatum" : 0,
"bestellangaben" : "BLOCK2",
"information1" : "blocktest",
"erstellungsdatum" : 1499414714,
"vorgabeauftragsnummer" : 87475003,
},
"ordertype" : "BLOCK2",
"customernnummer" : "981927",
"ordernumber" : 87475003,
"positions" : [
{ "artikelnummer" : 7081200,
"menge" : 3,
"bruttopreis" : 10,
"_id" : ObjectId("5960925ebe8fc415341c7d8f")
}
],
"date" : "2017-07-07",
"type" : "WERBUNG"
}
/*5*/
{
"_id" : ObjectId("596093ebbe8fc415341c7d90"),
"header" : {
"kundennummer" : "962422",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499501507.75201,
"vorgabeauftragsnummer" : 87475004,
},
"ordertype" : "",
"customernnummer" : "962422",
"ordernumber" : 87475004,
"positions" : [
"artikelnummer" : 3545900,
"menge" : 4,
"bruttopreis" : 100,
"_id" : ObjectId("596093ebbe8fc415341c7d95")
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*6*/
{
"_id" : ObjectId("596098e9be8fc415341c7ddf"),
"header" : {
"kundennummer" : "981927",
"auftragsdatum" : 0,
"bestellangaben" : "BLOCK3",
"information1" : "blocktest",
"erstellungsdatum" : 1499415886,
"vorgabeauftragsnummer" : 87475007,
},
"ordertype" : "BLOCK3",
"customernnummer" : "981927",
"ordernumber" : 87475007,
"positions" : [
{
"artikelnummer" : 1006199,
"menge" : 7,
"bruttopreis" : 10,
"_id" : ObjectId("596098e9be8fc415341c7de6")
}
],
"date" : "2017-07-07",
"type" : "WERBUNG"
}
/*7*/
{
"_id" : ObjectId("59609a47be8fc415341c7de7"),
"header" : {
"kundennummer" : "981225",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499503113.21714,
},
"ordertype" : "",
"customernnummer" : "981225",
"ordernumber" : 87475008,
"positions" : [
{
"_id": ObjectId("59609a47be8fc415341c7e0d")
"artikelnummer" : 2308400,
"menge" : 8,
"bruttopreis" : 100,
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*8*/
{
"_id" : ObjectId("59609a47be8fc415341c7e0e"),
"header" : {
"vorgabeauftragsnummer" : 87475009,
"erstellungsdatum" : 1499416697,
"information1" : "blocktest",
"bestellangaben" : "",
"auftragsdatum" : 0,
"kundennummer" : "981927",
},
"ordertype" : "",
"customernnummer" : "981927",
"ordernumber" : 87475009,
"positions" : [
"_id" : ObjectId("59609a47be8fc415341c7e57"),
"bruttopreis" : 10,
"menge" : 9,
"artikelnummer" : 8017000
}
],
"date" : "2017-07-07",
"type" : "ANDERE"
}
// Query 1: Quantity of customers and order value by order type (WERBUNG, ANDERE) and day
db.getCollection('orders').aggregate([
{$unwind:"$positions"},
{$project: {
"_id": 1,
customer: "$header.customernnummer",
date: {$}ToString: {format: "%d-%m-%Y", }: {"$add":[ new }(0), {"$multiply": [1000, "$header.erstellungsdate"]}]} }},
edate: "$header.erstellungsdate",
ordertype: "$header.ordertype",
type: {$cond: { if: {$ne: ["$header.ordertype" ,""]} , then: "WERBUNG", else: "ANDERE" }},
value: {$multiply: ["$positions.price","$positions.quantity"]},
}
},
{$group: {
_id: {type: "$type", tag: "$date",customer: "$customer" },
type: {$first: "$type"},
date: {$first: "$date"},
wert: {$sum: "$value" }
}
},
{$project:{
_id : 0,
customer: "$customer",
type: "$type",
date: "$date",
wert: "$wert"
}
}
,{$group: {
_id: {typ: "$type", date: "$date"}, customerQuantity:{$sum:1},
value: {$sum: "$wert"}
}
},
{$sort:{
typ: 1, date: -1
}
}
]}
// Query 2: Order quantity by type, date
...
{$project: {
block: {$cond: { if: {$ne: ["$auftragskopf.bestellangaben" ,""]} , then: "WERBUNG", else: "ANDERE" }},
datum: {$dateToString: {format: "%d-%m-%Y", date: {"$add":[ new Date(0), {"$multiply": [1000, "$auftragskopf.erstellungsdatum"]}]} }},
}
},
{$group:{
_id: {block: "$block", datum: "$datum"},
auftragsanzahl:{$sum:1},
}
},
I'm not sure about how your data looks like, but I understand from this line
type: {$cond: { if: {$ne: ["$header.ordertype" ,""]} , then: "WERBUNG", else: "ANDERE" }}
that if your $header.ordertype is WERBUNG then you want your order type to be WERBUNG otherwise its ANDERE. With that in mind here is my solution.
db.getCollection('orders').aggregate([
{
$project: {
"_id": 1,
header: 1,
positions: 1,
date: {
$dateToString: {
format: "%Y-%m-%d",
date: {
"$add": [new Date(0), {
"$multiply": [1000, "$header.date"]
}]
}
}
},
type: {
$cond: {
if: {
$eq: ["$header.ordertype", "WERBUNG"]
},
then: "WERBUNG",
else: "ANDERE"
}
}
}
},
{
$group: {
_id: {
type: "$type",
date: "$date"
},
werbungCount: {
$sum: {
$cond: [{
$eq: ['$type', 'WERBUNG']
}, 1, 0]
}
},
andereCount: {
$sum: {
$cond: [{
$eq: ['$type', 'ANDERE']
}, 1, 0]
}
},
customer: {
$first: "$header.customernnummer"
},
date: {
$first: "$date"
},
type: {
$first: "$type"
},
positions: {
$first: "$positions"
}
}
},
{
$unwind: "$positions"
},
{
$project: {
"_id": 1,
customer: "$customer",
date: 1,
ordertype: "$header.ordertype",
type: "$type",
value: {
$multiply: ["$positions.price", "$positions.quantity"]
},
price: "$positions.price",
quantity: "$positions.quantity",
orderQuantity: {
$cond: {
if: {
$eq: ["$type", "WERBUNG"]
},
then: "$werbungCount",
else: "$andereCount"
}
},
}
},
{
$group: {
_id: {
type: "$type",
tag: "$date",
customer: "$customer"
},
type: {
$first: "$type"
},
date: {
$first: "$date"
},
wert: {
$sum: "$value"
},
orderQuantity: {
$first: "$orderQuantity"
}
}
},
{
$group: {
_id: {
typ: "$type",
date: "$date"
},
orderQuantity: {
$first: "$orderQuantity"
},
value: {
$sum: "$wert"
}
}
},
{
$sort: {
typ: 1,
date: -1
}
}
])
I use the first $project to "normalize" the date. So an order placed at 1499415886: Friday, July 7, 2017 8:24:46 AM and 1499415990: Friday, July 7, 2017 8:26:30 AM will both be counted since they are on the same date (cause I could also tell from what you wrote that the time doesn't matter to you, only the date)
In the $group after the $project you just count the documents that have the "ordertype" WERBUNG and set them to the field werbungCount, otherwise if they are empty set them to the field andereCount. The pipeline after the $project and the $group is like you did it. I just corrected some mistakes and changed the name of the fields in some spots. Also added the orderQuantity field with a condition on the second $project.
Hope that works!
Working with mongolite v0.9.1 (R) and MongoDB v3.4, I'd like to join two collections, the first one, the parent containing an ObjectId, the second one, the children containing the string value of the parents' ObjectId.
This is the basic syntax :
conParent$aggregate('[
{ "$lookup":
{ "from":"Children",
"localField": "_id",
"foreignField": "parent_id",
"as": "children"
}
}
]')
$lookup seems to take only field name, I've tried this, producing syntaxic errors :
.../...
"foreignField": "{'$oid':'parent_id'}"
.../...
So is there a way to deal with that ?
In the other way, I tried to save the parent's ObjectId in the children in ObjectId format with no luck (I still get a string in MongoDB) :
result <- transform(
computeFunction,
parent_id = sprintf('{"$oid":"%s"}',parent$"_id"))
resultCon <- conout$insert(as.data.frame(result))
Is it possible to store an Id as ObjectId in mongolite?
Note : I'm doing bulk inserts so I can't deal with JSON string manipulations.
Any idea ?
Edit:
Here is an example of the collections i am using :
The Parent collection :
{
"_id" : ObjectId("586f7e8b837abeabb778d2fd"),
"name" : "Root1",
"date" : "2017-01-01",
"value" : 1.0,
"value1" : 10.0,
"value2" : 100.0
},
{
"_id" : ObjectId("586f7ea4837abeabb778d30a"),
"name" : "Root1",
"date" : "2017-01-02",
"value" : 2.0,
"value1" : 20.0,
"value2" : 200.0
}
The Children collection :
{
"_id" : ObjectId("586f7edf837abeabb778d319"),
"name" : "Item1",
"value" : 1.1,
"date" : "2017-01-01",
"parent_id" : "586f7e8b837abeabb778d2fd"
}
{
"_id" : ObjectId("586f7efa837abeabb778d324"),
"name" : "Item2",
"value1" : 11.111111111,
"value2" : 12.222222222,
"date" : "2017-01-01",
"parent_id" : "586f7e8b837abeabb778d2fd"
}
{
"_id" : ObjectId("586f7f15837abeabb778d328"),
"name" : "Item1",
"value" : 2.2,
"date" : "2017-01-02",
"parent_id" : "586f7ea4837abeabb778d30a"
}
{
"_id" : ObjectId("586f7f2b837abeabb778d32e"),
"name" : "Item2",
"value1" : 21.111111111,
"value2" : 22.222222222,
"date" : "2017-01-02",
"parent_id" : "586f7ea4837abeabb778d30a"
}
Could you try :
"foreignField": "_id"
Starting from mongo's website example :
library(mongolite)
library(jsonlite)
a = '[{ "_id" : 1, "item" : 1, "price" : 12, "quantity" : 2 },
{ "_id" : 2, "item" : 2, "price" : 20, "quantity" : 1 },
{ "_id" : 3 }]'
b= '[{ "_id" : 1, "sku" : "abc", "description": "product 1", "instock" : 120 },
{ "_id" : 2, "sku" : "def", "description": "product 2", "instock" : 80 },
{ "_id" : 3, "sku" : "ijk", "description": "product 3", "instock" : 60 },
{ "_id" : 4, "sku" : "jkl", "description": "product 4", "instock" : 70 },
{ "_id" : 5, "sku": null, "description": "Incomplete" },
{ "_id" : 6 }]'
mongo_orders <- mongo(db = "mydb", collection = "orders")
mongo_orders$insert(fromJSON(a))
mongo_inventory <- mongo(db = "mydb", collection = "inventory")
mongo_inventory$insert(fromJSON(b))
df <- mongo_orders$aggregate('[
{
"$lookup":
{
"from": "inventory",
"localField": "item",
"foreignField": "_id",
"as": "inventory_docs"
}
}
]')
str(df)
It works as well when both are set to _id
"localField": "_id",
"foreignField": "_id",
Well I must say that's not possible at all !
Mongilite retrieve _id as character and do not contain any ObjectId implementation.
So...