how to reach vue object properties to show them on head - vue.js

I have a table where i show people's some properties. As these properties can be extended in the future, i need to show all the available properties in table head, and the related answers to those properties under table body
I can reach the people's properties with the syntax:
v-for='person in people' and {{people.name}}
But i need to dynamically write 'Name' to table head.
Is there any option to reach to the object properties like name, age, salary, country, etc. ?
ex: people={name:john, surname: black, age:35, country:german}
<table class="table table-filter">
<thead>
<tr>
<th>Key</th>
<th>Name</th>
<th>Age</th>
<th>Whatever</th>
</tr>
</thead>
<tbody>
<tr>
<td>Value</td>
<td>John</td>
<td>35</td>
<td>Green</td>
</tr>
<tr>
<td>Value</td>
<td>Selin</td>
<td>23</td>
<td>Black</td>
</tr>
</tbody>

As with v-for directive you can cycle not only arrays, but objects also, just use second, nested v-for directive. Generic example:
<thead>
<tr>
<th v-for="val, key in person[0]"> // with first object in array
{{ key }} // show key - name for each column
</th>
</tr>
</thead>
<tbody>
<tr v-for="person, idx in people" :key="idx"> // with whole array
<td v-for="val, key in person"> // with each object in array
{{ val }} // show value for each column
</td>
</tr>
</tbody>

Accordibg to your sample data people={name:john, surname: black, age:35, country:german}
Key value in horizontal Table
<table>
<tr>
<th v-for="(value, index) in people">
{{ index }}
</th>
</tr>
<tr>
<td v-for="(value, index) in people">
{{ value }}
</td>
</tr>
<table>
Key value in vertical Table
<table>
<tr v-for="(value, index) in people">
<th>
{{ index }}
</th>
<td>
{{ value }}
</td>
</tr>
<table>

Related

laravel sql group

this is how i fetch my data;
$order_piece = CollectionOrder::select('collection_order.id', 'collection_color.color_name', 'collection_color_size_barcode.size', 'collection_color_size_barcode.id as ccsb_id', DB::raw('SUM(order_piece.piece) As piece'))
->join('order_piece', 'order_piece.order_id', '=', 'collection_order.id')
->join('collection_color', 'collection_color.id', '=', 'collection_order.collection_color_id')
->join('collection_color_size_barcode', 'collection_color_size_barcode.id', '=', 'order_piece.collection_color_size_barcode_id')
->where('collection_order.cut_id', $request->cut_id)
->groupBY('collection_color_size_barcode.size')
->groupBY('collection_order.collection_color_id')
->get();
blade code;
<table class="table table-hover table-light">
<thead>
<tr>
<th> size </th>
<th> piece </th>
</tr>
</thead>
#foreach($order_piece as $op)
<tr>
<td> {{$op->size}} </td>
<td> {{$op->piece}} </td>
</tr>
#endforeach
</table>
the data is like this;
[{"id":12,"color_name":"\u00c7ok Renkli","size":"34","ccsb_id":29,"piece":"82"},{"id":11,"color_name":"K\u0131rm\u0131z\u0131","size":"34","ccsb_id":24,"piece":"82"},{"id":13,"color_name":"\u00c7ok Renkli","size":"36","ccsb_id":30,"piece":"123"},{"id":10,"color_name":"K\u0131rm\u0131z\u0131","size":"36","ccsb_id":25,"piece":"123"},{"id":13,"color_name":"\u00c7ok Renkli","size":"38","ccsb_id":31,"piece":"123"},{"id":10,"color_name":"K\u0131rm\u0131z\u0131","size":"38","ccsb_id":26,"piece":"123"},{"id":12,"color_name":"\u00c7ok Renkli","size":"40","ccsb_id":32,"piece":"82"},{"id":11,"color_name":"K\u0131rm\u0131z\u0131","size":"40","ccsb_id":27,"piece":"82"},{"id":12,"color_name":"\u00c7ok Renkli","size":"42","ccsb_id":33,"piece":"41"},{"id":11,"color_name":"K\u0131rm\u0131z\u0131","size":"42","ccsb_id":28,"piece":"41"}]
I want to list this data by color. but it didn't occur to me. I want to list the size of each color regularly. like the example in the picture, can you help?

VueJS2 and Lodash4: How to nest v-for with another v-for in an HTML table?

I am having trouble getting some computed data to display properly in my HTML table. How can I replace the x placeholder content in the table with the values from my filteredFieldsWithOldValues() method?
Let me explain.
I have some data like so:
Codesandbox working demo: https://codesandbox.io/s/country-old-and-new-forked-s4zh7?file=/src/App.vue:51-599
{
"name": "Canada",
"entryType": 2,
"shortName": "CanadaEH",
"shortName_old": "Canada",
"fullName": "The NEW Republic of Canada",
"fullName_old": "The Republic of Canada",
"entryNotes": "Changed the short name and full name ",
"entryNotes_old": "fixed typo on short name"
}
Using lodash, I am filtering out fields that have the string _old appended to them and also filtering out some additional fields I do not want to show in the data. Overall, it looks like this:
filteredFieldsWithNewValues() {
const fieldsWithNoOldString = omitBy(this.country, (v, k) =>
k.endsWith("_old")
);
const omittedFields = omit(fieldsWithNoOldString, [
"updateStatus",
"entryType",
"name",
]);
return omittedFields;
},
This works fine and my data is displaying properly in the HTML table:
However, I need to replace the x placeholder in the table with the values from the keys that have _old appended to them. I tried to do it like so:
filteredFieldsWithOldValues() {
const fieldsWithOld = pickBy(this.country, (v, k) => k.endsWith("_old"));
return fieldsWithOld;
},
And then in my HTML table I put another v-for on the <tr>'s element like so:
<td v-for="(x, index) in filteredFieldsWithOldValues" :key="index">
{{ x }}
</td>
So, the updated HTML looks like so:
<table class="table">
<thead>
<tr>
<th scope="col">Field</th>
<th scope="col">Old</th>
<th scope="col">New</th>
</tr>
</thead>
<tbody>
<tr
v-for="(value, field, index) in filteredFieldsWithNewValues"
:key="index"
>
<th scope="row">{{ field }}</th>
<td v-for="(x, index) in filteredFieldsWithOldValues" :key="index">
{{ x }}
</td>
<td>{{ value }}</td>
</tr>
</tbody>
</table>
But now, the table is not displaying the values correctly.
How can I correctly show the values from the keys with _old correctly?
Try this
<table class="table">
<thead>
<tr>
<th scope="col">Field</th>
<th scope="col">Old</th>
<th scope="col">New</th>
</tr>
</thead>
<tbody>
<tr
v-for="(value, field, index) in filteredFieldsWithNewValues"
:key="index"
>
<th scope="row">{{ field }}</th>
<td>{{ filteredFieldsWithOldValues[field + '_old'] }}</td>
<td>{{ value }}</td>
</tr>
</tbody>
</table>

If the object name of array with space in v-for

The object name has space like 'Apple Juice','Orange Juice', so how can I use it in v-for?
<div id="box" v-if="!loading">
<table>
<thead>
<tr>
<th>Name</th>
<th>Total Sales</th>
</tr>
</thead>
<tbody>
<tr v-for="name in Beverage" v-bind:key="name">
<td>{{name.Txn Group}}</td> //error
<td>{{name.TotalSales}}</td>
</tr>
</tbody>
</table>
</div>
I called API and get JSON data, so I unable to change the object name.
Thanks.
You can write it like {{ name['Txn Group'] }} and it will work properly.

Quanitiy Shipped in odoo Invoice report

I'm trying to get the value qty of products shipped to display as an additional column in the invoice report. Not sure if its as simple as finding out what variable it is or what. Is there any easy way to reference what variables are available for the current views?
<table class="table table-condensed">
<thead>
<tr>
<th>Description</th>
<th class="hidden">Source Document</th>
<th class="text-right">Ordered</th>
<th class="text-right">Shipped</th>
<th class="text-right">Backorder</th>
<th class="text-right">Unit Price</th>
<th t-if="display_discount" class="text-right">Disc.(%)</th>
<th class="text-right">Extended Price</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<tr t-foreach="o.invoice_line_ids" t-as="l">
<td><span t-field="l.name"/></td>
<td class="hidden"><span t-field="l.origin"/></td>
<td class="text-right">
<span t-field="l.quantity"/>
<span t-field="l.uom_id" groups="product.group_uom"/>
</td>
<td class="text-right">
<span t-field="o.delivery_count"/>
</td>
<td class="text-right">
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td t-if="display_discount" class="text-right">
<span t-field="l.discount"/>
</td>
<td class="text-right">
<span t-field="l.price_subtotal" t-options="{"widget": "monetary", "display_currency": o.currency_id}"/>
</td>
</tr>
</tbody>
I don't exactly know what you mean with "products shipped" but you can get the quantity of the invoice lines to your report like this:
<t t-foreach="o.invoice_line_ids" t-as="l">
<span t-field="l.quantity"/>
</t>
Same for the stock picking lines quantity:
<t t-foreach="o.move_lines" t-as="l">
<span t-field="l.product_uom_qty"/>
</t>
One easy way to get the variable names is to activate the develop mode and placing the cursor over a field label.
You can also go to Settings->Database Structure->Models then just pick your needed model to see the variable names (field names).

Angular datatables - missing sort arrows when columns defined with DTColumnBuilder

I'm using Angular-datatables and when I define the table using the angular renderer I can see nice arrows for sorting column.
<table class="dataTable row-border hover" datatable="ng" dt options="vm.dtOptions">
<thead>
<tr>
<th class="secondary-text">
<div class="table-header">
<span class="column-title">My header</span>
</div>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ex in ::vm.exes">
<td>{{ex.myValue}}</td>
</tr>
</tbody>
</table>
When I define the columns with DTColumnBuilder.newColumn the arrows are missing (sorting works).
<table datatable="" dt-options="vm.dtOptions" dt-columns="vm.dtColumns"
class="dataTable row-border hover"
dt-disable-deep-watchers="true"
dt-instance="vm.dtInstanceCallback">
</table>
and
vm.dtColumns = [
DTColumnBuilder.newColumn('myValue').withTitle('My header'),
Can I bring the sorting arrows back?