I have a simple datatable with PrimeVue, where I can add columns like below:
<Column field="destination" header="Destination"></Column>
This will render a column with the field destination for that specific row. However, in some cases, the destination will be null. Is there an easy way to define a default value - or do I have to use templating like below?
<Column field="destination" header="Destination" :sortable="true">
<template #body="slotProps">
{{ slotProps.data.destination ?? 'N/A' }}
</template>
</Column>
The reason why I don't want to use the template and slotProps is simply because I have a very large datatable with +50 columns, and this just looks messy.
Related
I have the below datatable with a strange behavioir:
<DataTable
:scrollable="true"
:value="shipments"
:totalRecords="shipments.length"
:reorderableColumns="true"
:alwaysShowPaginator="false"
:paginator="true"
:rows="10"
:resizableColumns="true"
columnResizeMode="fit"
sortMode="multiple"
:stripedRows="true"
removableSort
dataKey="reference"
responsiveLayout="scroll">
<template #empty> No records found </template>
<Column field="reference" header="Shipment Number" :sortable="true" frozen />
<Column header="Shipper" style="text-transform: capitalize">
<template #body="slotProps">
{{ slotProps.data.shipper.name.toLocaleLowerCase() }}
</template>
</Column>
</DataTable>
If I try to reorder (dragging) the columns, I get the below error. Every time I try to reorder, the reference column is added to the table.
[Vue warn]: Duplicate keys found during update: "reference" Make sure keys are unique.
If I remove this part of the Shipper column:
<template #body="slotProps">
{{ slotProps.data.shipper.name.toLocaleLowerCase() }}
</template>
And just reference the shipper name using field="shipper.name" it works fine without any errors.
What am I doing wrong?
Reading through the documentation I can see that I missed an important part when using the reorderColumns functionality.
I need to set a columnKey if the specific column doesn't have a field defined as per the docs:
If the column has no field, use columnKey instead as it is mandatory for columns to have unique keys when reordering is enabled.
I added this, and it works now:
<Column header="Shipper" columnKey="shipper" style="text-transform: capitalize">
<template #body="slotProps">
{{ slotProps.data.shipper.name.toLocaleLowerCase() }}
</template>
</Column>
I'm trying to create an simple SQL TDE template for XML documents in Marklogic DB.
Sample template:
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/match</context>
<collections>
<collection>source1</collection>
</collections>
<rows>
<row>
<schema-name>soccer</schema-name>
<view-name>matches</view-name>
<columns>
<column>
<name>id</name>
<scalar-type>long</scalar-type>
<val>id</val>
</column>
<column>
<name>document</name>
<scalar-type>string</scalar-type>
<val>docUri</val>
</column>
<column>
<name>date</name>
<scalar-type>date</scalar-type>
<val>match-date</val>
</column>
<column>
<name>league</name>
<scalar-type>string</scalar-type>
<val>league</val>
</column>
</columns>
</row>
</rows>
</template>
I have inserted a sample document in the content database and the above template into Schemas database.
Now I'm trying to run a SQL query using XQuery as below:
xdmp:sql("select * from matches","map")
The above query returns the below response
soccer.matches.id
soccer.matches.document
soccer.matches.date
soccer.matches.league
1234567
/soccer/match/1234567.xml
2016-01-12
Premier
In json format it is,
[
{
"soccer.matches.id": 1234567,
"soccer.matches.document": "/soccer/match/1234567.xml",
"soccer.matches.date": "2016-01-12",
"soccer.matches.league": "Premier"
}
]
In the above response the key name is returned as schema-name.view-name.column_name.E.g.,soccer.matches.id
But I need the key name to have only the column name.E.g., "id": 1234567
Could anyone please share the easiest way to achieve this in XQuery?
You could probably se the names in the SQL statement using AS. You could always iterate over thr the results in a FLWOR statement to modify your results.
However, I suggest that you use the optic API and tune the results as you wish.
Using an op:from-view would be the suggested course of action. You could still use op:from-sql(). In both cases, experiment with the qualifier parameter including omitting it . For the final results, you can use an op:as() with op:select() or op:group-by() to define exactly what you want.
Optic API reference: https://docs.marklogic.com/guide/app-dev/OpticAPI
Optic Functions:
https://docs.marklogic.com/op
I have the following table
<b-table
ref='table'
:fields='fields'
:items='provider'
:busy.sync='isBusy'
>
<template v-slot:bottom-row>
<!-- TODO: Is it possible to not hardcode it? -->
<b-td colspan='7' class='text-center'>
<b-spinner></b-spinner>
</b-td>
</template>
</b-table>
Is it possible to somehow get the column count and use it in the colspan instead of hardcoded 7? I presume I can use some convoluted logic with a custom prop to cover this but there's probably a better approach. I can also use e.g. 999999 which surprisingly works.
I've tried colspan='fields.length' but that wouldn't work.
You were so close with your try
In order for vue to understand that you want to pass a variable as the attribute value, you need to add a colon in front of it, like so:
<b-td :colspan='fields.length' class='text-center'>
If you do it like this:
<b-td colspan='fields.length' class='text-center'>
colspan would parse the fields.length as a string "fields.length", not the javascript computed value for the variable fields.length 7 for example.
This seems to remain unanswered so here is another attempt at a solution.
Currently in bootstrap-vue, I am rendering a b-table. I would like to improve this by having the ability to select a row and collapse/expand an extra div/row/etc to show further information.
In the below snippet you will see what I am trying. The problem is that I can't seem to get the expanded data to span the number of columns in the table. I have tried adding <tr><td colspan="6"></td></tr> but it doesn't seem to span like I would expect. Any workarounds for this? Thanks.
<b-table
:items="case.cases"
:fields="tableFields"
head-variant="dark">
<template
slot="meta.status"
slot-scope="data">
<b-badge
v-b-toggle.collapse1
:variant="foobar"
tag="h6">
{{ data.value }}
</b-badge>
</template>
<template
slot="#id"
slot-scope="data">
<span
v-b-toggle.collapse1>
{{ data.value }}
</span>
<b-collapse id="collapse1">
Collapse contents Here
</b-collapse>
</template>
</b-table>`
Sounds like you could use the Row Details slot:
If you would optionally like to display additional record information (such as columns not specified in the fields definition array), you can use the scoped slot row-details
<b-table :items="case.cases" :fields="tableFields" head-variant="dark">
<template slot="meta.status" slot-scope="data">
<b-button #click="data.toggleDetails">
{{ data.value }}
</b-button>
</template>
<template slot="row-details" slot-scope="data">
<b-button #click="data.toggleDetails">
{{ data.detailsShowing ? 'Hide' : 'Show'}} Details }}
</b-button>
<div>
Details for row go here.
data.item contains the row's (item) record data
{{ data.item }}
</div>
</template>
</b-table>
There is a good example in the docs at https://bootstrap-vue.js.org/docs/components/table#row-details-support
I (think) I had the same issue, and I came up with a solution which leverages the filtering functionality of the bootstrap-vue <b-table> to achieve the effect of expanding and collapsing rows.
There's a minimal example in a JSFiddle here:
https://jsfiddle.net/adlaws/mk4128dg/
Basically you provide a tree structure for the table like this:
[
{
columnA: 'John', columnB:'Smith', columnC:'75',
children:
[
{ columnA: 'Mary', columnB:'Symes', columnC:'46' },
{ columnA: 'Stan', columnB:'Jones', columnC:'42' },
{ columnA: 'Pat', columnB:'Black', columnC:'38' },
]
}
]
The tree is then "flattened" out to rows which can be displayed in a table by the _flattenTreeStructure() method. During this process, the rows are also annotated with some extra properties to uniquely identify the row, store the depth of the row (used for indentation), the parent row of the row (if any) and whether or not the row is currently expanded.
Once this is done, the flattened structure can be handed to the <b-table> as it is just an array of rows - this is done via the computed property flattenedTree.
The main work now is done by the _filterFunction() method which provides custom filtering on the table. It works off the state of the expandedRowIndices property of the filterObj data item.
As the expand/collapse buttons are clicked, the row index (as populated during the flattening process) is inserted as a key into expandedRowIndices with a true or false indicating its current expanded state.
The _filterFunction() uses this to "filter out" rows which are not expanded, which results in the effect of expanding/collapsing a tree in the table.
OK, so it works (yay!), but...
it's not as flexible as the base <b-table>; if you want to show different columns of data, you'll need to do some work and to re-do the <template slot="???"> sections for the columns as required.
if you want to actually use filtering to filter the content (with a text search, for example) you'll need to extend the custom filter function to take this into account as well
sorting the data is not something I had to do for my use case, and I'm not sure how it would work in the context of a tree structure anyway - maintaining the tree's parent/child relationships while changing the order of the rows around would be... fun, and I suspect this would be a nice challenge to implement for someone who is not as time poor as me. ;)
Anyway, I hope this is of use to someone. I'm reasonably new to Vue.js, so there may be a better way to approach this, but it's done the job I needed to get done.
<ngx-datatable
id="ngxdatatable"
class='material striped'
[rows]="rows"
[columns] ="columns"
>
</ngx-datatable>
I tried to bind columns, which columns are getting at run time using columns properties from class object.
I want to style a specific column using cell class using css. How this can be achieved. Please help
I would recommend looking at some of the source code for styling header and column cells as well as how to create column templates, such as:
https://github.com/swimlane/ngx-datatable/blob/master/demo/basic/css.component.ts and https://github.com/swimlane/ngx-datatable/blob/master/demo/basic/row-detail.component.ts
You can style the column headers by adding the [headerClass]="insertYourCssClassName" inside the column template tag like this:
<ngx-datatable-column
name="ID"
prop="id"
[headerClass]="insertYourCssClassNameHere"
>
Same thing goes for styling the body cells, only with [cellClass] instead of [headerClass].