Improve checkbox click handling support for grids

i.e. let custom use define click handlers
This commit is contained in:
Lance Edgar 2019-10-31 17:55:44 -05:00
parent a857d31776
commit bcfb4f257d
5 changed files with 96 additions and 10 deletions

View file

@ -93,6 +93,10 @@ Vue.component('grid-filter', GridFilter)
let TailboneGrid = {
template: '#tailbone-grid-template',
props: {
csrftoken: String,
},
computed: {
// note, can use this with v-model for hidden 'uuids' fields
selected_uuids: function() {
@ -120,14 +124,14 @@ let TailboneGrid = {
this.loading = true
this.$http.get(`${this.ajaxDataUrl}?${params}`).then(({ data }) => {
this.data = data.data
TailboneGridCurrentData = data.data
this.data = TailboneGridCurrentData
this.rowStatusMap = data.row_status_map
this.total = data.total_items
this.firstItem = data.first_item
this.lastItem = data.last_item
this.loading = false
// TODO: should "merge" checked results from server?
this.checkedRows = []
this.checkedRows = this.locateCheckedRows(data.checked_rows)
})
.catch((error) => {
this.data = []
@ -137,6 +141,18 @@ let TailboneGrid = {
})
},
locateCheckedRows(checked) {
let rows = []
if (checked) {
for (let i = 0; i < this.data.length; i++) {
if (checked.includes(i)) {
rows.push(this.data[i])
}
}
}
return rows
},
onPageChange(page) {
this.page = page
this.loadAsyncData()
@ -244,6 +260,14 @@ let TailboneGrid = {
uuids.push(row.uuid)
}
return uuids
}
},
allRowUUIDs() {
let uuids = []
for (let row of this.data) {
uuids.push(row.uuid)
}
return uuids
},
}
}