Quasar Q-Table and Data from Array (IndexedDB & Dexie) - qtableview

I am new to Quasar and Javascript and I'm trying to get data from my database (IndexedDB using Dexie) into my q-table.
I have the skeleton of the q-table and I'm getting the data from Dexie, in the form of an Array, but I don't know how to display the data in the table and I would love some help.
I've read about maybe having to use computed, and/or the map option but I don't know enough about either of those to use them. I've been googling and reading the Quasar docs and I'm still not sure what to do. I don't know if I can put it in a codepen since it's getting data from a database.
I have this live online at https://entrypaws.com/ you may have to hit shift-reload to get the latest version as my host has an online cache it keeps, though I've cleared it. This small table section is reachable by clicking the 'view test table' link in the left sidebar.
Here is my html:
<q-page>
wholething: {{ this.thePersonArray }} // this displays correc
<br/><br/>
hmmm: {{ this.thePersonArray[0].f_lastName }}
<q-table
title="Treats"
:rows="rows"
:columns="columns"
row-key="name"
binary-state-sort
>
<template v-slot:body="props">
<q-tr :props="props">
<q-td key="name" :props="props">
{{ props.row.name }}
</q-td>
<q-td key="lname" :props="props">
{{ props.row.lname }}
</q-td>
<q-td key="dogbreed" :props="props">
<div class="text-pre-wrap">{{ props.row.dogbreed }}</div>
</q-td>
<q-td key="phone" :props="props">
{{ props.row.phone }}
</q-td>
</q-tr>
</template>
</q-table>
</q-page>
</template>
and this is my script:
import { ref } from "vue"
import theDB from "../components/dexiedb.js"
const columns = [
{
name: 'name',
label: 'First Name',
field: row => row.name, // f_lastname:
},
{ name: 'lname', label: 'Last Name', field: 'lname'},
{ name: 'dogbreed', label: 'Dog Breed', field: 'dogbreed'},
{ name: 'phone', label: 'Phone', field: 'phone'},
]
const rows = [
{
name: 'Susan',
lname: 'Smith',
dogbreed: 'Danish-Swedish Farmdog',
phone: '801.810.9990',
},
{
name: 'James',
lname: 'Jones',
dogbreed: 'Kromfohrlander',
phone: '801.930.9999',
},
]
export default {
name: "testtable",
setup() {
return {
columns,
rows
}
}, // end setup
data() {
return {
thePersonArray: [],
}
}, // end data
created() {
this.getTheUsers()
}, // end mounted
methods: {
getTheUsers() {
this.thePersonArray = []
console.log(" getTheUsers 1 ", this.thePersonArray)
this.thePersonArray.push({f_lastName: "Dreamer"}) // if the array is not initialized i seem toget an error
theDB.personTable
.orderBy('f_lastName')
.each((personOBJ) => {
this.thePersonArray.push(personOBJ)
console.log(" inside: ", this.thePersonArray)
}).then(() => {
// Transaction committed.
console.log(" People: Transaction committed")
}).catch(err => {
// Transaction aborted.
console.log(" People: Transaction aborted")
})
console.log(" after done: ", this.thePersonArray)
}
}, // end methods
} // end export
</script>```
I'd love some help. I'm completely stuck.
[1]: https://entrypaws.com/

Try making thePersonArray reactive by using ref
data() {
return {
thePersonArray: ref([]),
}
},
then assign the new array to thePersonArray.value
getTheUsers() {
this.thePersonArray.value = []
I think you might be able to push directly with thePersonArray as I think Vue maps/ wraps/ proxies these methods (whatever they call it :) ), so try
this.thePersonArray.push({f_lastName: "Dreamer"})
and if that doesnt work try
this.thePersonArray.value.push({f_lastName: "Dreamer"})
but I think the first will work

Related

Filter Data before Rendering Highcharts

I have a Highcharts Gantt chart which is pulling parsed JSON data from a MySQL table.
The data spans 4 years, but I need to filter it so that it only shows data for 2022.
The issue is that I cannot use the standard Highcharts data filter as it does not remove empty rows without any data.
I would like to filter the data before the chart is even rendered so that rows without bars are not shown at all. Is that possible?
It is really easy, you just need to filter your JSON data before creating a chart. A simplified process will be like below:
const receivedData = [{
name: 'Start prototype',
start: '2021-04-11',
end: '2021-04-17'
}, {
name: 'Test prototype',
start: '2022-04-11',
end: '2022-04-17'
}, {
name: 'Develop',
start: '2022-06-11',
end: '2022-07-11'
}, {
name: 'Run acceptance tests',
start: '2022-09-11',
end: '2022-09-21'
}];
const filteredData = receivedData.filter(
dataEl => new Date(dataEl.start) > new Date('2022')
);
// THE CHART
Highcharts.ganttChart('container', {
series: [{
name: 'Project 1',
data: filteredData.map(({
name,
start,
end
}) => ({
name,
start: new Date(start).getTime(),
end: new Date(end).getTime()
}))
}]
});
Live demo: https://jsfiddle.net/BlackLabel/0vhdg5jw/

Dynamic table component that automatically list each property value of the current Object data iteration (ngFor directive);

Going to the point, I'm creating a table component that receives an Object containing all information that the dynamic table needs, including head information and so on. My mission is to make it possible for every row (data), my table doesn't need to know the property name, only list its value straight away.
I did some console tests and it seems to work around those lines:
const dataList = [
{ name: 'Eugene', age: 20, alive: true },
{ name: 'Game Master', age: 40, alive: false },
{ name: 'Camel', age: 22, alive: true }
];
for(let data of dataList) {
console.log("All data info");
console.log(data);
for(let propertyValue of Object.values(data)) {
console.log(propertyValue);
}
}
The Results:
VM1123:2 All data info VM1123:3 {name: 'Eugene', age: 20, alive:
true} VM1123:6 Eugene VM1123:6 20 VM1123:6 true
VM1123:2 All data info VM1123:3 {name: 'Game Master', age: 40,
alive: false} VM1123:6 Game Master VM1123:6 40 VM1123:6
false VM1123:2 All data info VM1123:3 {name: 'Camel', age:
22, alive: true} VM1123:6 Camel VM1123:6 22 VM1123:6
true
I'm trying to achieve the same result, but this time iterating between ngFor directive, like below:
<tr *ngFor="let data of tableConfig.data; let i = index">
<td *ngFor="let propValue of Object.values(data)"> {{ propValue }}</td>
But, the problem is that I can't access the 'Object' class inside the component HTML.
Property 'Object' does not exist on type 'PaginationTableComponent'.
Add method to get your object values like
getValues(data): any{
return Object.values(data);
}
In template :
<td *ngFor="let propValue of getValues(data)"> {{ propValue }}</td>
Demo

Angular 4 dropdown multiselect not showing property data

I just installed angular 4 multiselect dropdown to show the data that i am getting from JSON script using services. I am getting the data in my property but now i want to show it in a multiselect dropdown so that i can use multiple values and assign them to my next property. So in the below code i am calling a method of getSubject and it is returning me the data in this.subject property.
this._curriculumService.getSubject(this.appSession.tenant.tenancyName)
.finally(() => {this.saving = false;})
.subscribe((result: listResultDtoOfSubjectDto) => {
this.subjects = result.items;
this.id = this.subjects.map(a => a.code);
this.itemName = this.subjects.map(a => a.name);
})
Now i want to show this data inside inside angular 4 dropdown multiselect and here is a code for that in my component.ts file. The problem is that the dropdown asked for a specific id and name of the property and only then it will be able to show the data in dropdown but in my case i have a name and code returning in this.subjects. So how can i show my data in this dropdown
optionsModel: number[];
myOptions: IMultiSelectOption[];
this.myOptions = [
{ id: 1, name: 'Physics' },
{ id: 2, name: 'English' },
{ id: 3, name: 'English' },
{ id: 4, name: 'Programming'}
];
HTML Code
<div class="form-line focused">
<div class="col-sm-4">
<div class="form-group form-float">
<div class="form-line focused">
<ss-multiselect-dropdown
[options]="myOptions"
[(ngModel)]="optionsModel"
(ngModelChange)="onChange($event)">
</ss-multiselect-dropdown>
</div>
</div>
</div>
</div>
So for that don't declare type of your myOptions as IMultiSelectOption[], instead keep it any or whatever you're receiving from service. As this plugin requires each options to have the id thus, you can add that property to myOptions objects after it's received from service response. So, make sure that property should be unique valued (e.g. subject code).
Let this.subjects is an array of objects you got from service:
optionsModel: number[];
subjects: any;
this.subjects = [
{ code: 11, name: 'Physics' },
{ code: 12, name: 'English' },
{ code: 13, name: 'English' },
{ code: 14, name: 'Programming'}
];
this.subjects.forEach(function(e) { e.id = e.code });
The last line will add id property to each object with value same to subject code. Now the dropdown will work as expected.
Demo Example

Laravel: How do I parse this json data in view blade?

Currently this is my view
{{ $leads }}
And this is the output
{"error":false,"member":[{"id":"1","firstName":"first","lastName":"last","phoneNumber":"0987654321","email":"email#yahoo.com","owner":{
"id":"10","firstName":"first","lastName":"last"}}]}
I wanted to display something like this
Member ID: 1
Firstname: First
Lastname: Last
Phone: 0987654321
Owner ID: 10
Firstname: First
Lastname: Last
It's pretty easy.
First of all send to the view decoded variable (see Laravel Views):
view('your-view')->with('leads', json_decode($leads, true));
Then just use common blade constructions (see Laravel Templating):
#foreach($leads['member'] as $member)
Member ID: {{ $member['id'] }}
Firstname: {{ $member['firstName'] }}
Lastname: {{ $member['lastName'] }}
Phone: {{ $member['phoneNumber'] }}
Owner ID: {{ $member['owner']['id'] }}
Firstname: {{ $member['owner']['firstName'] }}
Lastname: {{ $member['owner']['lastName'] }}
#endforeach
it seems you can use #json($leads) since laravel 5.5
https://laravel.com/docs/5.5/blade
For such case, you can do like this
#foreach (json_decode($leads->member) as $member)
{{ $genre }}
#endforeach
You can use json decode then you get php array,and use that value as your own way
<?php
$leads = json_decode($leads, true);
dd($leads);
The catch all for me is taking an object, encoding it, and then passing the string into a javascript script tag. To do this you have to do some replacements.
First replace every \ with a double slash \\ and then every quote" with a \".
$payload = json_encode($payload);
$payload = preg_replace("_\\\_", "\\\\\\", $payload);
$payload = preg_replace("/\"/", "\\\"", $payload);
return View::make('pages.javascript')
->with('payload', $payload)
Then in the blade template
#if(isset($payload))
<script>
window.__payload = JSON.parse("{!!$payload!!}");
</script>
#endif
This basically allows you to take an object on the php side, and then have an object on the javascript side.
in controller just convert json data to object using json_decode php function like this
$member = json_decode($json_string);
and pass to view in view
return view('page',compact('$member'))
in view blade
Member ID: {{$member->member[0]->id}}
Firstname: {{$member->member[0]->firstname}}
Lastname: {{$member->member[0]->lastname}}
Phone: {{$member->member[0]->phone}}
Owner ID: {{$member->owner[0]->id}}
Firstname: {{$member->owner[0]->firstname}}
Lastname: {{$member->owner[0]->lastname}}
Example if you have array format like this:
$member = [
[ "firs_name" => "Monica",
"last_name" => "Dev",
"sex" => "F"
],
[ "firs_name" => "Blake",
"last_name" => "Devante",
"sex" => "M"
],
[ "firs_name" => "Johnny",
"last_name" => "Merritt",
"sex" => "M"
]
]
You can use #json Blade directive for Laravel 5.5 to 9.x
<script>
var app = #json($member);
</script>
From Laravel 8.x to latest version you can use Illuminate\Support\Js::from method directive.
<script>
var app = {{ Illuminate\Support\Js::from($member) }};
</script>
And for short with Js facade
<script>
var app = {{ Js::from($array) }};
</script>
Reference:
https://laravel.com/docs/blade
If your data is coming from a model you can do:
App\Http\Controller\SomeController
public function index(MyModel $model)
{
return view('index', [
'data' => $model->all()->toJson(),
]);
}
index.blade.php
#push('footer-scripts')
<script>
(function(global){
var data = {!! $data !!};
console.log(data);
// [{..}]
})(window);
</script>
#endpush
Just Remove $ in to compact method ,
return view('page',compact('member'))

Sencha Touch 2 read values from key AND value from nested JSON

I am trying to load some JSON, in which I store a lot of variables about some 100 anaesthetic drugs for pediatric patients.
The actual values get calculated before from patient's weight, age etc.:
Example:
var propofolInductionTitle = propofolName + ' ' + propofol0PercentConcentration + '- Induktion';
var propofol0InductionDosageMG = (Math.round(kg * 2 * 10) / 10) + ' - ' + (Math.round(kg * 5 * 10) / 10);
I then create my drug as a block of json consisting of the variables I need which are later to be replaced by the calculated values. I specifically try to avoid Strings in the JSON to allow for easier localization to english and french when all variables are defined in the math block.
var hypnotikaJSON = {
"thiopentalTitle": [
{"thiopentalBrandName": ""},
{"vialContentTitle": "thiopentalVialContent"},
{"solutionTitle": "thiopentalSolution"},
{"concentrationTitle": "thiopentalConcentration"},
{"dosageString": "thiopentalDosageString"},
{"atWeight": "thiopentalDosageMG"},
{"thiopentalAtConcentration": "thiopentalDosageML"}
],
"propofolInductionTitle": [
{"propofolInductionBrandName": ""},
{"propofolVialContentTitle": "propofolInductionVialContent"},
{"propofolSolutionTitle": "propofolSolution"},
{"propofolConcentrationTitle": "propofolInductionConcentration"},
{"propofolInductionDosageStringTitle": "propofolInductionDosageString"},
{"atWeight": "propofolInductionDosageMG"},
{"propofolAtInductionConcentration": "propofolInductionDosageML"}
],
"propofolSedationTitle": [
{"propofolSedationBrandName":""},
{"propofolVialContentTitle":"propofolSedationVialContent"},
{"propofolSolutionTitle":"propofolSolution"},
{"propofolConcentrationTitle":"propofolSedationConcentration"},
{"propofolSedationDosageStringTitle":"propofolSedationDosageString"},
{"atWeight":"propofolSedationDosageMG"},
{"propofolAtSedationConcentration":"propofolSedationDosageML"}
],
"laryngealMaskTitle": [
{"laryngealMaskSizeTitle":"laryngealMaskSize"},
{"laryngealMaskCuffSizeTitle":"laryngealMaskCuffSize"},
{"laryngealMaskBiggestETTTitle":"laryngealMaskBiggestETT"},
{"laryngealMaskBronchoscopeSizeTitle":"laryngealMaskBronchoscopeSize"}
]
};
My specific need is that the JSON reader has to give me the key AND value of each object as I need both to populate a template. The reason ist that the fields for the drugs are different in parts. Some have additional routes of administration so I have another key:value pair a different drug doesnt have. Some are given both as bolus and per drip, some arent. So no convenient json structure ist possible.
I found an answer by rdougan here that partly allowed me to do just that:
Model:
Ext.define('my.model.Drug', {
extend: 'Ext.data.Model',
config: {
fields: ['name', 'value']
}
});
Custom Json Reader:
Ext.define('Ext.data.reader.Custom', {
extend: 'Ext.data.reader.Json',
alias: 'reader.custom',
getRoot: function (data) {
if (this.rootAccessor) {
data = this.rootAccessor.call(this, data);
}
var values = [],
name;
for (name in data) {
values.push({
name: name,
value: data[name]
});
}
return values;
}
});
Store:
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'value'],
data: hypnotikaJSON,
autoLoad: true,
proxy: {
type: 'memory',
reader: {
type: 'custom'
}
}
});
Panel:
this.viewport = new Ext.Panel({
fullscreen: true,
layout: 'fit',
items: [{
xtype: 'list',
itemTpl: '<p class="description">{name}</p><p class ="values">{value}</p>',
store: store
}]
});
Unfortunately I'm a physician and no programmer, and after a lot of reading I cant find out to apply this to a nested JSON. The custom reader seems to only go for the first level.
I could do it without a reader, without a store with just a lot of plan html around each entry, that has proven to be very very slow though so I would like to avoid it while updating from Sencha Touch 1.1. and better do it right this time.
Could you please point me to a way to parse this ugly data structure?
Thank you
I don't know much about extending JSON readers, so just guessing, but maybe you are supposed override the 'read' method? Then you can go over the JSON as you wish
Also, if you have control over the JSON you should consider changing it.
Usually, the keys in JSON should be the same throughout all items in the array.
keys are not data, they are metadata.
So, if you do have different properties between different drugs, then something like this might be a solution:
[{
name: 'Propofol 1%',
properties: [
{title: 'induction', value: '22-56g'},
{title: 'Sedation', value: '22'},
etc.
]},
{name: 'nextDrug'}
etc..