Need a special offer?Find out if your project fits.
+

How to map a filed to a complex property of my model?

Answered
Ilaria asked on July 23, 2018

Hi,
is there any way to customize the display text of a cell in the pivotGrid?
My model is like:
[
{
category: 'FOOD'
productId: '2938752809572057809991350991'
productDescription: 'Product EVO',
saleDate: '2018-07-19T16:11:07+02:00'
qty: 100
},
{
category: 'FOOD'
productId: '2q46246262641378561789356298'
productDescription: 'Product TUNA',
saleDate: '2018-07-19T16:11:07+02:00'
qty: 200
}
];
I would like to see the caption 'Product EVO' but in the onClick event I would like to have the information about the productID, and I would like to see only the field 'ProductDescription' in the available fields (not 'ProductId')
In other word: the correct representation of my data is like
[
{
category: 'FOOD'
product: {
id: '2938752809572057809991350991',
description: 'Product EVO'
},
saleDate: '2018-07-19T16:11:07+02:00'
qty: 100
},
{
category: 'FOOD'
product: {
id: '2q46246262641378561789356298',
description: 'Product TUNA'
},
saleDate: '2018-07-19T16:11:07+02:00'
qty: 200
}
]
so, one 'complex' field Product with description (used as display text) and id (used for my internal logic) and I would like to have both informations in the cell-object:
onCellClick = function (cell) {
if (cell && cell.rows.length && cell.rows[cell.rows.length - 1].hierarchyUniqueName === 'product') {
var productInfo = cell.rows[cell.rows.length - 1];
var productId = productInfo.id;
var productDescription = productInfo.caption;
doStuff(productId, productDescription);
}
}
I saw that there is a way to put the fileds in a 'hierarchy' but this is not exactly what I need, because, in order to have the information about the ProductID, the user is forced to display that field and click on it.

6 answers

Public
Dmytro Zvazhii Dmytro Zvazhii Flexmonster July 24, 2018

Hello Ilria,
Thank you for your question. Could you please specify what pivot's view you are going to use when implementing such behavior? Is it a flat view, or maybe a compact or classic view? 
Waiting for your feedback.
Regards,
Dmytro

Public
Ilaria July 24, 2018

Hi Dmytro!
Actually, I would like to implement this behavior in all the three view. Don't look at my specific implementation of 'onCellClick', it was just an example to explain my target.
Anyway, as a first step, it could be enough to have this possibility in the compact and classic view.
Thank you!
Best regards,
Ilaria

Public
Tanya Gryshko Tanya Gryshko Flexmonster July 24, 2018

Hello, Ilaria,
Thank you for a quick update!
I would like to inform you that there is an approach that will work for a flat view. The first object in the JSON array can be used to define data types. There you can define an "id" type, which will not be shown in Field List. This data type can be used for productId and you will have access to it. For more details and an example please refer to the following forum thread: https://www.flexmonster.com/question/what-is-suggested-approach-to-combine-data-from-two-cells/.
As for the compact and classic views, such approach does not work because each cell represents the aggregated value of several records.
Let us know whether the approach for the flat view works for your case.
Also, could you please specify how critical such behavior in the compact and classic view for your project?
Regards,
Tanya

Public
Ilaria July 26, 2018

 
Hi Tanya,
I need this feature mainly in compact and classic view (the flat view is only an additional feature for my project).
My task is to port an existing desktop application (with a pivotGrid in compact and classic view) to a web application and so I'm trying to explore different choices for the pivotGrid control.
The main functionality that I have to implement is the editing of aggregate values, in compact or classic view.
I'm leaning to choose your pivot grid control for many reasons (such as conditional formatting, multiple views, integration with chart...) but the problem outlined above is crucial for my choice.
I already tried the use of type 'id' in the flat view and since this field is unique for each data, I understand why it is not implemented in the other views: an aggregate cell could have multiple values for the field id in the underlying data, because that field is not used in the aggregation function.
But, even using this field, I should adapt it to my structure: I exposed in the example the problem for the field 'Product' but i have the same issue for other fields such as 'Customer' (and so on), so I'm forced to use one single field for both productId and customerId (may be concatenating them with a separator, not mentioning the fact that I h no control on
the datasource and so the split may cause problems if customerId or ProductId contains the separator). Anyway this could be a solution only for flat view and this is not enough for my project.
The best solution for me is to have the possibility to define a complex field with id and decription. There are two chioices at this point: aggregate data by the couple [id, description] or aggregate by id and show
an aggragation function of description, such as max for instance (aggregate by [id, Max(description)]. I do not know if I made it clear. If you need more explanations please let me know.
Thank you for yout time!
Regards, 
Ilaria

Public
Illia Brazhko Flexmonster July 30, 2018

Hi Ilaria!
 
Thanks a lot for the information you provided. We have contacted you via email with more details about this case.
 
Kind regards,
Illia

Public
Ilaria July 30, 2018

Thank you for your time!
Best regards, 
Ilaria

Please login or Register to Submit Answer