Skip to content

Commit

Permalink
fix bugs with sort
Browse files Browse the repository at this point in the history
  • Loading branch information
xaksis committed Nov 18, 2017
2 parents 537753b + 0c6c244 commit 0dc85ca
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ myStyleFn(row){
<td>enables filtering on column (By default, creates a text input)</td>
<td>Boolean</td>
</tr>
<tr>
<td>placeholder</td>
<td>placeholder to use for filter input</td>
<td>String</td>
</tr>
<tr>
<td>filterDropdown</td>
<td>provides a dropdown for filtering instead of a text input</td>
Expand Down
24 changes: 21 additions & 3 deletions dev/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<div>
<vue-good-table :columns="columns" :rows="rows" :line-numbers="true">
<vue-good-table
:paginate="true"
:columns="columns"
:rows="rows"
:line-numbers="true">
<template slot="table-row-before" scope="props">
<td><input type="checkbox" /></td>
</template>
Expand All @@ -21,7 +25,8 @@
return {
columns: [
{
label: ''
label: '',
sortable: false,
},
{
label: 'Name',
Expand All @@ -34,7 +39,8 @@
type: 'number',
},
{
label: ''
label: '',
sortable: false,
},
],
rows: [
Expand Down Expand Up @@ -68,6 +74,18 @@
}, {
name: "Dan",
age: "40"
}, {
name: "Jane",
age: "24"
}, {
name: "Susan",
age: "16"
}, {
name: "Chris",
age: "55"
}, {
name: "Dan",
age: "40"
},
],
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<div class="datatable-length pull-left">
<label>
<span>{{rowsPerPageText}}</span>
<span v-if="perPage" class="perpage-count">{{perPage}}</span>
<select v-if="!perPage" class="browser-default" @change="perPageChanged">
<!-- <span v-if="perPage" class="perpage-count">{{perPage}}</span> -->
<select class="browser-default" @change="perPageChanged">
<option v-if="perPage" :value="perPage">{{perPage}}</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
Expand Down
33 changes: 23 additions & 10 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<tr>
<th v-if="lineNumbers" class="line-numbers"></th>
<th v-for="(column, index) in columns"
:key="column.field"
@click="sort(index)"
:class="getHeaderClasses(column, index)"
:style="{width: column.width ? column.width : 'auto'}"
Expand All @@ -42,8 +43,11 @@
</tr>
<tr v-if="hasFilterRow">
<th v-if="lineNumbers"></th>
<th v-for="(column, index) in columns" v-if="!column.hidden">
<div v-if="column.filterable" :class="getHeaderClasses(column, index)">
<th v-for="(column, index) in columns"
:key="column.field"
v-if="!column.hidden">
<div v-if="column.filterable"
:class="getHeaderClasses(column, index)">
<input v-if="!column.filterDropdown"
type="text"
class=""
Expand All @@ -59,6 +63,7 @@
<option value="">{{ getPlaceholder(column) }}</option>
<option
v-for="option in column.filterOptions"
:key="option"
:value="option">
{{ option }}
</option>
Expand All @@ -70,21 +75,30 @@
:value="columnFilters[column.field]"
v-on:input="updateFilters(column, $event.target.value)">
<option value="">{{ getPlaceholder(column) }}</option>
<option v-for="option in column.filterOptions"
:value="option.value">{{ option.text }}</option>
<option
v-for="option in column.filterOptions"
:key="option"
:value="option.value">{{ option.text }}</option>
</select>

</div>
</th>
</tr>
</thead>

<tbody>
<tr v-for="(row, index) in paginated" :class="getRowStyleClass(row)" @click="click(row, index)">
<tr
v-for="(row, index) in paginated"
:key="index"
:class="getRowStyleClass(row)"
@click="click(row, index)">
<th v-if="lineNumbers" class="line-numbers">{{ getCurrentIndex(index) }}</th>
<slot name="table-row-before" :row="row" :index="index"></slot>
<slot name="table-row" :row="row" :formattedRow="formattedRow(row)" :index="index">
<td v-for="(column, i) in columns" :class="getClasses(i, 'td')" v-if="!column.hidden && column.field">
<td
v-for="(column, i) in columns"
:key="column.field"
:class="getClasses(i, 'td')"
v-if="!column.hidden && column.field">
<span v-if="!column.html">{{ collectFormatted(row, column) }}</span>
<span v-if="column.html" v-html="collect(row, column.field)"></span>
</td>
Expand Down Expand Up @@ -273,11 +287,10 @@
//Get classes for the given header column.
getHeaderClasses(column, index) {
const isSortable = this.isSortableColumn(index);
const isDescending = this.sortColumn === index && this.sortType === 'desc';
const classes = Object.assign({}, this.getClasses(index, 'th'), {
'sorting': isSortable,
'sorting-desc': isSortable && isDescending,
'sorting-asc': isSortable && !isDescending
'sorting-desc': isSortable && this.sortColumn === index && this.sortType === 'desc',
'sorting-asc': isSortable && this.sortColumn === index && this.sortType === 'asc',
});
return classes;
},
Expand Down

0 comments on commit 0dc85ca

Please sign in to comment.