Show encoded data from Redis - angularjs

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\":143748‌​7498449,\"period\":2,\"newUser\":0}")
http://www.w3schools.com/angular/tryit.asp?filename=try_ng_tables_simple

Related

How to retrieve the rows from starting and ending index in firebase database

I am trying pagination feature in my project, I am using react with firebase.
My problem statement: if I have around 50 records in my database, what is the query if we want to select records 3 - 8?
If you want to use specific fields in front-end side then use slice and i think you can return your all list from backend and just slice from ui side.
let arr = [
{id:1,name:'One'},
{id:2,name:'Two'},
{id:3,name:'Three'},
{id:4,name:'Four'},
{id:5,name:'Five'},
{id:6,name:'Six'},
{id:7,name:'Seven'},
{id:8,name:'Eight'},
{id:9,name:'Nine'},
{id:10,name:'Ten'}
]
let selected = arr.slice(2,8);
console.log(selected)
Firebase Realtime Database doesn't have numeric index pagination. The API allows you to start at the beginning and page through the query results using startAt(), limitToFirst(), and other related methods, as described in the documentation.
If you absolutely must use indexes, you will have to read the entire set of results, populate an array, and pick out the desired results from that array using the indexes you want on the page.

Using the same filter control for two different data sources

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

Create pivot table from Google App Maker datasource

I have exported data from Google App Maker(2) into spreadsheet. The problem is, I have to do pivot table manually in the exported sheet in order to get the table such as in no(3). Image(1) show the field that I have in the datasource.
(1) Screenshot of what I have in my datasource
(2) Data exported from AppMaker into Spreadsheet
(3) Expected pivot table to be exported
Can anyone teach me how to query data from the existing datasource to produce another table such as in no(3) in Google App Maker directly, so that I just export that data directly to sheet and no need to do pivot manually after the data has been exported .. or is there anyway better than that anyone else know how to do it?
I would rather to go with some nice charts to layout these stats... but if you want to go Sheets way you'll need to do some scripting with Apps Script Sheets Advanced API.
// server side code
function addPivotTable_(spreadsheetId, pivotSourceDataSheetId, destinationSheetId) {
var requests = [{
// Request object goes here
}];
var response = Sheets.Spreadsheets.batchUpdate({'requests': requests}, spreadsheetId);
}

Angular UI Grid show encoded data

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}")
];

Ng-Grid Multiple Filtering in Column

Let's say I had one of many columns of data in an ng-grid like so:
Status
Open
Closed
Open
Closed
Pending
Pending
Closed
I can filter for just one, but can I have multiple filters using ng-grid? For example, filtering for 'Open' gives me back all the ones that are 'Open', but what if I wanted to get back both 'Open' and 'Closed'? So the result would be like:
Status
Open
Closed
Open
Closed
Closed
Thanks for any help!
Asuming that you are using PHP/MySQL on your server side I would use this approach:
Enter something like Open|Closed in the filter input. (or use any separator you like)
This search string will be send to your server.
At the server explode() this search string into an array.
$search=explode("|",$searchstring);
Then generate a sql query from that array.
Example code:
//The searchstring that was send via ajax
$searchstring="Open|Closed";
//The field in the DB you want to filter
$field="status";
//Generate the where condition
$search=explode("|",$searchstring);
$whereCond="";
while (list($key, $val) = each($search)) {
$whereCond.= "`".$field."` ='".$val."' OR " ;
}
//remove the last unnecessary OR
$whereCond = substr_replace( $whereCond, "", -3 );
//Generate the query
$query="SELECT * FROM `table` WHERE ( ".$whereCond." )";
//Fetch data from the DB and return it to your App
This should generate a query like:
SELECT * FROM `table` WHERE ( `status` ='Open' OR `status` ='Closed' )
This way you can enter as many OR conditions as you want.
Watch out for the proper amount of spaces and use the correct quotes for the query.
In case you are using another stack, you have to figure out your own query generator. But basically it comes down to this approach. If you are using server sided data you have to do the filtering on the server side.
A client sided example can be found on the official ng-grid site here.
The Server-Side Paging Example is in fact client sided, it just fetches a large json file from the server.

Resources