Is there a way to display data in format
"{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}"
to show them separately (every piece of data in appropriate column - column1 - Id, column2 - brand etc.) in the table(single row)?
I parse (JSON.parse) the data, but I cannot separate them and show in appropriate column - all data go to first column.
I'm trying to reproduce plunkr
UI-Grid takes an array of objects as data, so you need to contain your json in an array. Just add brackets around your parsed json object.
$scope.myData = [JSON.parse("{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}")];
Same holds for multiple json objects:
$scope.myData = [
JSON.parse("{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}"),
JSON.parse("{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}")
];
Related
We use FiveTran to extract our data from shopify and store it in BigQuery. The field "properties" within the order_line table contains what looks like an array of key/value pairs. In this case name/value. The field type is string here is an example of the contents
order_line_id properties
9956058529877 [{"name":"_order_bump_rule_id","value":"4afx7cbw6"},{"name":"_order_bump_bump_id","value":"769d1996-b6fb-4bc3-8d41-c4d7125768c5"},{"name":"_source","value":"order-bump"}]
4467731660885 [{"name":"shipping_interval_unit_type","value":null},{"name":"charge_delay","value":null},{"name":"charge_on_day_of_week","value":null},{"name":"charge_interval_frequency","value":null},{"name":"charge_on_day_of_month","value":null},{"name":"shipping_interval_frequency","value":null},{"name":"number_charges_until_expiration","value":null}]
4467738738773 [{"name":"shipping_interval_unit_type","value":null},{"name":"charge_delay","value":null},{"name":"charge_on_day_of_week","value":null},{"name":"charge_interval_frequency","value":null},{"name":"charge_on_day_of_month","value":null},{"name":"shipping_interval_frequency","value":null},{"name":"number_charges_until_expiration","value":null}]
4578798600277 [{"name":"shipping_interval_unit_type","value":null},{"name":"charge_interval_frequency","value":null},{"name":"shipping_interval_frequency","value":null}]
I am trying to write a query that generate one row per record with a column for each of these name values:
shipping_interval_unit_type
charge_on_day_of_week
charge_interval_frequency
charge_on_day_of_month
subscription_id
number_charges_until_expiration
shipping_interval_frequency
and the corresponding "value". This field "properties" can contain many different "name" values and they can be in different order each time. The "name" values noted above are not always present in the "properties" field.
I've tried json functions but it doesn't seem to be properly formatted for json. I've tried unnesting it but that fails since it is a string.
Consider below approach
select * from (
select order_line_id,
json_extract_scalar(property, '$.name') name,
json_extract_scalar(property, '$.value') value
from your_table, unnest(json_extract_array(properties)) property
)
pivot (min(value) for name in (
'shipping_interval_unit_type',
'charge_on_day_of_week',
'charge_interval_frequency',
'charge_on_day_of_month',
'subscription_id',
'number_charges_until_expiration',
'shipping_interval_frequency'
))
I'm using npgsql to store data about shipments and part of table is jsonb column storing some details about shipment including details about customer who made shipment.
Table for displaying data about shipments is displaying only Customer Name and if get that record via
CustomerName = shipment.Metadata.RootElement.GetProperty("customer").GetProperty("customerName").ToString(),
Request is that I make this column sortable so I would need to sort by this property while accessing database.
Is it even possible to do it in NpgSql?
You can easily sort by a property inside a JSON document - just specify that property in your OrderBy clause:
_ = await ctx.Shipments
.OrderBy(s => s.Metadata.RootElement.GetProperty("customer").GetProperty("customerName").GetString())
.ToListAsync();
This produces the following:
SELECT s."Id", s."Metadata"
FROM "Shipments" AS s
ORDER BY s."Metadata"#>>'{customer,customerName}'
You should probably be able to make this use an index as well.
I have a Data Studio report containing two graphs.
Each graph is associated with a different data source. Each data source has one common field (ex: country) but shouldn't be joined together.
Currently I have to set one filter control for each data source and it is not friendly user. I want to use the same filter control (ex: country) to set the country in the 2 charts.
Is there a way to do so ?
I have a not elegant solution for that:
Have you tried create a custom field on the 2 different data sources?
go to Data Source "A" -> Add Field -> put the function CONCAT(Country_A, '') -> copy the field_ID
go to Data Source "B" -> add field -> put the function (Country_B, '') -> PASTE & OVERWRITE the field_ID.
Use on of the custom fields you have created as control filter, it will filter data in both datasources (as field_ID matches on both sources)
More details:
Let say we have Data Source "A" & "B" and the field Country is the one that we want to make 'match' across those 2 data sources. What I do is basically create a new field on one data source by using the CONCAT(fieldName, '') function. You need to create the first custom field and then you need to "SAVE" or "COPY" the field ID.
Then you go to the second data source, create a new Custom Field, following the same function CONTACT(fieldName, '') and OVERWRITE the Field_ID that Datastudio assigned by the one you have copied.
As a best practice, I always put the same Field Name on both custom fields.
Heads-up!
Be aware that if you have a list of 10 countries on data source A and a list of 20 countries on data source B, then depending on what custom field you choose to the control filter, you will have less or more options to filter. Also, this workaround does not "merge" values on both data sources. I would recommend to do a pre-processing with your data and add a data Source "C" which contains all possible countries and do the same workaround 3 times (1 custom field per data source).
Emmanuel Roulleau
its possible, filter controls work in reports with multiple data sources.
Filter control is a page-level component they effects all the charts on that page, if you want to use the same filter control to set the country in the 2 charts, Group them.
ctrl + select the charts and the filter control then Arrange -> Group
Check this embedded report https://datastudio.google.com/s/meLMNkz7ejY
So a filter control for the Analytics charts can use the Country dimension from either data source.
For more info Check This link https://support.google.com/datastudio/answer/9173975
I have encoded data
"{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}"
which I publish with command: PUBLISH channel "{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}"
Then I retrieve these data (Node.js) and successfully show them on the frontend (Angular) in one line as a message.
I want to show them in table(UI grid) - (column1 - Id, column2 - brand etc.)
Is there a way to parse these data to show them separately (every piece of data in appropriate column) in the table?
In angular, to display data in a table you can use 'ng-repeat'.For details go through this URL:http://www.w3schools.com/angular/angular_tables.asp
Use JSON.parse then use ng-repeat
var parsedData = JSON.parse("{\"brand\":\"newBrand\",\"Id\":\"1\",\"field\":\"1\",\"date\":1437487498449,\"period\":2,\"newUser\":0}")
http://www.w3schools.com/angular/tryit.asp?filename=try_ng_tables_simple
Is it possible to use Data transformers to merge (n) fields in a form into one persistable field?
If it's possible, how to do it? The cookbook only gives an example to transform one piece of data into another type, but I need to be able to dump N fields into only one for persistence. So if I'm showing 6 fields in the form, only 3 are real fields in DB table, first and second fields are to persisted as is, but the remaining 4 fields are to be store in the third table column.
You should do it via FormEvent::POST_SUBMIT event.
http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html
Basically, something like this:
$builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
$form = $event->getForm();
// entity or array
$data = $event->getData();
// get data directly from form
$concatData = $form->get('non_mapped_field1_1')->getData() . ',' . $form->get('non_mapped_field1_2')->getData();
// assumig that data is entity class
$data->setSomeField($concatData);
}
);