Comments (15)
@singhabahu I know its been a while but maybe this will help someone else, if you leave out the slot-scope attribute it should work:
<template slot="h__check">
<input type='checkbox' id='checkbox' @click='selectAllAtOnce()'>
</template>
from vue-tables-2.
How do I handle events on clicking the heading checkbox?
from vue-tables-2.
Here's how I'm handling events.
I have the template v-modeled to a selected property:
<v-client-table ref="myGrid" :data="tableData" :columns="myColumns">
<template slot="selected" scope="props">
<div>
<input v-model="props.row.selected" type="checkbox">
</div>
</template>
</v-client-table>
Here's the heading element:
headings: {
selected: function (h) {
return h('input', {
attrs: {
type: 'checkbox',
id: 'selectAllCheckbox'
},
on: {
click: (e) => {
this.selectAll(e.srcElement.checked)
}
},
ref: 'selectAllCheckbox'
})
},
I have a selectAll method that sets or unsets the underlying property when the heading is clicked:
selectAll(checked) {
let length = tableData.length
for (let i = 0; i < length; i++) {
if (checked) {
tableData[i].selected = true
} else {
tableData[i].selected = false
}
}
},
from vue-tables-2.
@jeff-pang @freeman-g @matfish2 I've been trying to add a checkbox for the table header but below code didn't work. However code to add checkbox to each row works fine.
<template slot="h__selected" slot-scope="props">
<input type='checkbox' id='checkbox' @click='selectAll()'>
</template>
any idea where I made the mistake?
Here's my code
{
tableColumns: [
"check",
"Name",
"WindowId",
"Enabled",
"Duration",
"Description"
],
tableData: [],
tableOptions: {
headings: {
Name: "Name",
WindowId: "Window ID",
Enabled: "Status",
Duration: "Duration",
Description: "Description"
},
sortable: ["Name", "WindowId", "Enabled", "Duration", "Description"],
filterable: ["Name", "WindowId", "Enabled", "Duration", "Description"]
}
This is how I render my table
<template slot="h__check" slot-scope="props">
<input type='checkbox' id='checkbox' @click='selectAllAtOnce()'>
</template>
from vue-tables-2.
following up on the @freeman-g 's example. an alternative to the render function selected
is to replace it using scope-slot like this
<!-- checkbox for each row-->
<template slot="selected" slot-scope="props">
<input type='checkbox' id='checkbox' v-model='props.row.isChecked'>
</template>
<!-- checkbox for each header (prefix column name with h__-->
<template slot="h__selected" slot-scope="props">
<input type='checkbox' id='checkbox' @click='selectAll()'>
</template>
define a variable to toggle check/uncheck states. in my example i use isSelected
selectAll() {
let length = this.tableData.length
this.isRead=!this.isSelected;
for (let i = 0; i < length; i++) {
this.tableData[i].isChecked=this.isSelected;
}
}
from vue-tables-2.
@JonathanLouw thanks for the input. will look into this when I get a free time.
from vue-tables-2.
I've been experimenting with ways to do this with templates. So far I have an implementation that shows the checkboxes but unfortuanately does not correctly move them on sorting.
from vue-tables-2.
I've added a possibility to pass a function to render dynamic HTML. E.g:
headings:{
title: function(h) {
return <h6><input type="checkbox"/>Title</h6>
}
}
Note that I'm using JSX, not HTML. Of course you can also write the node using plain JavaScript.
from vue-tables-2.
How can we add checkboxes to each row ? Apparently below code doesnt work for me
<template slot="selected" slot-scope="props"> <input type='checkbox' id='checkbox' v-model='props.row.isChecked'> </template>
from vue-tables-2.
JonathanLouw - Tnx much that one helped , seems 'h__' slot still do not like slot-scope="props" .
from vue-tables-2.
Thanks everyone.
Well I was able to add checkbox in header row as Select/Deselect All option for rows.
Btw, my problem is,
I want to use select all on filtered results only.
Or I want to select Row checkboxes when select HeaderRow checkbox for filtered/currently visible results on table only.
from vue-tables-2.
Thanks everyone.
Well I was able to add checkbox in header row as Select/Deselect All option for rows.Btw, my problem is,
I want to use select all on filtered results only.
Or I want to select Row checkboxes when select HeaderRow checkbox for filtered/currently visible results on table only.
Can I see your code for Header checkbox to select all/deselect all the rows? Thank you.
from vue-tables-2.
After banging my head on the wall for 4 hours, I finally found this thread. slot-scope dont work with h__ slots.
<template
v-for="column in columns"
:slot="`h__${column}`"
>
<div
:key="column"
v-html="options.headings[column]"
@click="clickhandler($event,column)"
/>
</template>
from vue-tables-2.
Hi,
My solution is working. maybe this is help other.
Please see it.
https://gist.github.com/hoai/dc37116f6a17a45232647dcfe8090e51
from vue-tables-2.
The header on my checkbox does not update with the "allSelected" variable. The only way to fix it that I found was to use a ref on the header and change the ".checked" var to true or false. The problem is that vue doesnt like when you change the prop directly.
HTML:
<v-client-table :columns="['name', 'select']" :data="products" :options="table.options" :theme="table.theme" class="dataTable p-0 m-0 w-100">
<div slot="h__select" style="float: right">
<b-checkbox @change="cart.selectedProducts = selectAll()" color="success" style="float: right"
v-model="allSelected"/>
</div>
<div slot="select" slot-scope="props" style="float: right">
<b-form-checkbox v-model="cart.selectedProducts" :value="props.row._id" color="success"
style="float: right" />
</div>
</v-client-table>
Vars:
data: () => {
return {
products: {
{name: "socks", _id: 1},
{name: "shirt", _id: 2},
{name: "pants", _id: 3},
},
cart: {
selectedProducts: [],
... // Other cart Data
},
allSelected: false,
... // Other Page Data
}
}
Watchers:
watch: {
selectedProducts: {
deep: true,
handler() {
let all = this.products.filter(product => {
return this.cart.selectedProducts.includes(product._id);
}
if (all.length === this.products.length) {
console.log("change to true")
this.allSelected = true;
} else {
console.log("change to false")
this.allSelected = false;
}
}
}
}
Methods:
methods: {
selectAll() {
let result = [];
let all = this.products.filter(product => {
return this.cart.selectedProducts.includes(product._id);
}
if (all.length === this.products.length) {
return result;
} else {
this.products.forEach(function (product, index) {
Vue.set(result, index, product);
})
return result;
}
}
}
from vue-tables-2.
Related Issues (20)
- Changelog HOT 3
- Row double click HOT 2
- Variables inside custom header not updating HOT 4
- Documentation of disabledChildRows option HOT 1
- Change header of toggle column HOT 2
- editable edits all rows on click HOT 1
- how to manage table refresh HOT 1
- MouseUp event conflicts with other MouseUp events HOT 2
- problem with virtual pagination height HOT 6
- grouping doesn't show data HOT 4
- evaluate removal of background: white from thead tr th HOT 2
- customize column header titles HOT 1
- [question] sort by attribute, show another HOT 2
- Replacing cell content issues HOT 2
- Custom components in vue 3 HOT 2
- Set initial listColumns in dropdown HOT 2
- Add 'large-desktop' columnDisplay value(s)
- xscode down HOT 41
- Does uniqueKey support nested objects? HOT 2
- How to access table data from custom template
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-tables-2.