Export Datatable parent and child data as excel in javascript - datatables

I am trying to export jQuery data table as excel, data table is having both parent and child records. when I am using data table exports, its only exporting parent level records but not child.
how to export parent and child data in an excel. below is the table
date price
+ 6/July 30
+ 7/July 40
+ 10/July 50
date price
- 6/July 30
John 10
Bobby 10
Kevin 5
Stella 5
+ 7/July 40
+ 10/July 50
export button is
Export All
and I am using the default functionality to export the data as excel.
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'excel'
]
} );

Related

How to return array of objects from other table postgres node js

Parent Table
id
name
1
ben
2
fred
3
david
Child Table
id
name
parent_id
1
sergey
1
2
jake
2
3
rudolp
1
I want to make a get request like this from my node server and this is my expected response.
also can you suggest best practices in this approach, I am thinking of getting all the data/table in server then looping on them to generate the array of objects . Thanks
[
{
id:1
name: "Ben",
childs:[{id: 1, name: "sergey"},{id: 3, name: "rudolp"}]
},
{
id:2
name: "Fred",
childs:[{id: 2, name: "Jake"}]
},
}
]

Extracting data from JSON in SQL

I have a column which holds the following data named events_payload:
{
"event": 'number_1"
}
,
"position":null,
"page_setup": {
"revision": 45190, "template":"\"This is\" new template", "date_modified":"2020-02-26 08:11:52", "category":"best-tv"
}
}
I am trying to create new columns by extracting the JSON so that I would have columns like so:
revision template date_modified category
45190 This is new template 2020-02-26 08:11:52 best-tv
I have tried the following:
SELECT
json_extract_path_text(events.event_payload::text, 'revision'::text, true) AS revision
But I do not know how to take what is inside the page_setup one element at a time.
How could I extract all 4 data fields into separate columns?
Thank you for your suggestions.

Alerting on sum of value of two fields in a document using Elast Alert

I want to alert on sum of two fields.
Each document will have only one of the two fields.
Ex:
{
"number1" : 30
}
{
"number2": 20
}
Above are the two documents under same index,
I want to alert if sum(sum(number1),sum(number2) in last one hour is less than some value
I have tried the below:
type: metric_aggregation
index: test-*
description: "Testing"
buffer_time:
minutes: 1
timestamp_field: "#timestamp"
doc_type: "doc"
metric_agg_key: number1
metric_agg_key: number2
metric_agg_type: sum
min_threshold: 70
alert:
- "email"
alert_subject: "FNot matching"
alert_text: |
Hi Team,s
alert_text_type: alert_text_only

Filtering through 2 differents components after rendering them

I'm stuck with this problem : I'm trying to order 2 same-level components who both have their own datas with their own properties. But the 2 differents datas have the same "position" property.
DB structure
Chapter
chapterId
title (string)
position (integer)
Page
pageId
name (string)
position (integer)
body (text)
Here is my Summary.vue
<template>
<div>
<summary-chapter v-for="chapter in data.chapters" :chapter="chapter"></summary-chapter>
<summary-page v-for="page in data.pages" :page="page"></summary-page>
</div>
</template>
The data variable is :
data :
{
'chapters' : { {chapterId: 1, ...}, {chapterId: 2, ...}, {chapterId: 3, ...}, ... },
'pages' : { {pageId: 1, ...}, {pageId: 2, ...}, {pageId: 3, ...}, ... }
}
I'm looking for this kind of results : Mixed
Pos: 1 - Page with id of 12
Pos: 2 - Chapter with id of 7
Pos: 3 - Chapter with id of 2
Pos: 4 - Page with id of 4
Pos: 5 - Page with id of 13
Pos: 6 - Chapter with id of 1
But I always have all chapters first and then all pages :
Pos: 2 - Chapter with id of 7
Pos: 3 - Chapter with id of 2
Pos: 6 - Chapter with id of 1
Pos: 1 - Page with id of 12
Pos: 4 - Page with id of 4
Pos: 5 - Page with id of 13
I really have no clue how to do it the right way.
I tried to filter through a computed data property
I try dto built a parent component Summary row taht contains a chapter component or a page component depending on the type
I try 100 other ways ... :(
Do you guys have a tip ?
Thanks in advance for your time.
Louis
One way to solve this problem is combine those two arrays then sort by its position:
computed: {
sortedItems () {
let chapters = this.chapters.map(chapter => ({ ...chapter, type: 'chapter' }))
let pages = this.pages.map(page => ({ ...page, type: 'page' }))
return []
.concat(chapters)
.concat(pages)
.sort((a, b) => (a.position - b.position))
}
}
Then in you template render it by type:
<template v-for='item in sortedItems'>
<summary-chapter v-if='item.type === "chapter"' :chapter='item'/>
<summary-page v-if='item.type === "page"' :page='item'/>
</template>

morris.js displaying difficulties

I have a morris.js graph. I have a table with 3 columns id with values such as 1,2,3 etc, usernames with values such as sophie, nick, Paul etc and timesloggedin with values such as 69, 58, 4 etc.
I created a chart that has the ids on x and the timesloggedin on y.
What I want is instead of displaying the id number on the bottom of the chart under the bars, to have their usernames. You can see the chart here:
http://kleanthisg.work/chartsnew2.php
CODE:
http://kleanthisg.work/CODE.TXT
table:
user list:
You need to provide the username and set it as xkey
Morris.Bar({
element : 'chart_line_1',
data:[{ id:'1', timesloggedin:65, username: 'Paul'},
{ id:'5', timesloggedin:10, username: 'John'},
{ id:'7', timesloggedin:4, username: 'Steve' }],
xkey:'username',
ykeys:['timesloggedin'],
labels:['timesloggedin'],
hideHover:'auto',
});