<template> <div class="col-lg-12 control-section">
<div>
<ejs-grid
ref="grid"
id="grid"
:dataSource="data"
allowSorting="true"
:sortSettings="initialSort"
:actionComplete="actionComplete"
>
<e-columns>
<e-column
field="OrderID"
headerText="Order ID"
width="100"
textAlign="Right"
:isPrimaryKey="true"
></e-column>
<e-column
field="CustomerID"
headerText="Customer ID"
width="100"
></e-column>
<e-column
field="Freight"
headerText="Freight"
width="100"
format="C2"
textAlign="Right"
></e-column>
<e-column
field="EmployeeID"
headerText="Employee ID"
width="100"
></e-column>
<e-column
field="OrderDate"
headerText="Order Date"
width="130"
:format="formatoptions"
textAlign="Right"
></e-column>
<e-column
field="ShipCountry"
headerText="Ship Country"
width="150"
></e-column>
<e-column
field="FirstName"
headerText="FirstName"
width="100"
></e-column>
<e-column
field="LastName"
headerText="LastName"
width="100"
></e-column>
</e-columns>
</ejs-grid>
</div>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
Edit,
CommandColumn,
Toolbar,
Group,
Sort,
ForeignKey,
} from "@syncfusion/ej2-vue-grids";
import { data } from "./datasource.js";
Vue.use(GridPlugin);
var c;
// var index;
export default {
data: function () {
return {
data: data,
formatoptions: { type: "date", format: "dd/MM/yyyy" },
initialSort: {
columns: [
{ field: "Freight", direction: "Ascending" },
{ field: "CustomerID", direction: "Descending" },
],
},
pageSettings: { pageCount: 5 },
};
},
methods: {
actionComplete: function (args) {
if (args.requestType === "sorting" && !args.direction) {
var index = args.target.closest("th").cellIndex;
var column = this.$refs.grid.ej2Instances.getColumnByIndex(index).field;
// here we sort the same column with Ascending direction by using sortColumn method when a repetitive third click on the same column this.$refs.grid.ej2Instances.sortColumn(column, "Ascending", true);
}
},
},
provide: {
grid: [Edit, Toolbar, Group, CommandColumn, Sort, ForeignKey],
},
};
</script> |