Adding header column in between existing header columns
While populating data-grid after getting an API response.
I have a problem statement where I need to add a new data-grid header in between the existing data-grid header while populating column data.
As in my case, I want to add a new header name as 'Order Date' in-between existing 'Order ID' & 'Order Status' while adding my column data.
Code :
datagrid.addColumn('Order ID', datagrid.DATA_TYPE_DOUBLE);
datagrid.addColumn('Order Status', datagrid.DATA_TYPE_STRING);
for(var i = 0; i < json_order_length; i++){
datagrid.addCell(jsonobj[i].id);
datagrid.addCell(jsonobj[i].status);
if(i === 3)
{
// it adds the column at last after Order Status
// but I want it between existing 'Order ID' & 'Order Status' header.
datagrid.addColumn('Order Date', datagrid.DATA_TYPE_DATETIME);
datagrid.addCell(jsonobj[i].date_created);
}
}
Please also refer to the image uploaded for more details.
Comments
-
Hi @user062862
If you want the order date to be before status you need to call datagrid.addColumn('Order Date'...) before the Order Status. Because you're adding Status column before the date column is what you're getting your current result.
Could you just add all 3 columns to start and then just add a null value (this is all an assumption as I don't know the structure of your JSON) when i = 3?
Something like this (untested - back of napkin code here):
datagrid.addColumn('Order ID', datagrid.DATA_TYPE_DOUBLE); datagrid.addColumn('Order Date', datagrid.DATA_TYPE_DATETIME); datagrid.addColumn('Order Status', datagrid.DATA_TYPE_STRING); for(var i = 0; i < json_order_length; i++){ datagrid.addCell(jsonobj[i].id); if(i === 3) { datagrid.addCell(jsonobj[i].date_created); } else { datagrid.addCell() } datagrid.addCell(jsonobj[i].status); }
My javascript is a bit rusty. You may need to do datagrid.addCell(null) instead of datagrid.addCell()
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
I can't pre-decide the column headers before writing the column data as the condition I gave here for easier understanding i.e. *i===3* but in reality it is something like *order has 3 products then add three new columns in-between "Product-1", "Product-2", "Product-3" * which is dynamic means a 1st person can have 3 products in orders & 2nd person can have 20 products in orders.
So while iterating through the order data we want to add headers existing between two headers.0 -
this may lead to problems down the road.
if you design a dataflow that injects columns based on the number of orders (prod_1, prod_2, prod_3) then you can potentially get a dataset with 100 extra columns.
from day to day, the number of columns might change based on the data in your dataset. as a result any downstream ETL that expects column (ex. prod_21) will break.
in this context your're probably off inserting ROWS instead of columnns.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
also... don't split hairs which order columns are added to your dataset. neither analyzer nor ETL tools really care about column order.
if you want to reorganize them for display purposes, just use a DataSetView (talk to your CSM) to reoganize them.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 755 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive