|
// Select single row
this.$refs.grid.ej2Instances.selectRow(22);
// Select multiple rows
this.$refs.grid.ej2Instances.selectRows([1,2,3]); |
|
OnCreated: function(args) {
var parent = this;
// Click event for selectrow button
document.getElementById("selectrow").addEventListener("click", event => {
parent.$refs.grid.ej2Instances.selectRow(parent.selectIndex);
var gridRowHeight = this.$refs.grid.ej2Instances.getRowHeight();
this.$refs.grid.ej2Instances.getContent().firstElementChild.scrollTop = this.selectIndex * gridRowHeight;
});
}, |
|
<ejs-grid :dataSource='data' height=300 :enableVirtualization=true :pageSettings='options'>
</ejs-grid>
export default {
name: 'app',
data() {
return {
options: { pageSize: 50 },
};
},
.
.
} |
|
<e-column field='TaskID' headerText='Task ID' width=70></e-column> |
|
// Grid’s dataBound event function
OnDataBound: function(args) {
// All the grid columns are returned
var gridColumns = this.$refs.gridColumns.ej2Instances.columns;
var count = 0;
while (count < gridColumns.length) {
gridColumns[count].headerText = 'Header text ' + count;
count++;
}
}, |
|
<e-column field='CreateUserID' headerText='Create User ID' :dataSource='userList' foreignKeyField='UserID' foreignKeyValue='UserName'></e-column> |
|
<e-column field='LatLng.Lat' headerText='Lat'></e-column>
<e-column field='LatLng.Lng' headerText='Lng'></e-column> |
|
// Grid’s actionBegin event function
actionBegin: function(args) {
if (args.requestType == "virtualscroll") {
// Get the current page value
var curPage = args.virtualInfo.page;
// Calculate the records to skip
var recordsToSkip = this.$refs.grid.ej2Instances.pageSettings.pageSize * (curPage - 1);
// Get the records to take
var recordsToTake = this.$refs.grid.ej2Instances.pageSettings.pageSize;
// With these value you can send request to your server
}
} |
|
this.$refs.grid.ej2Instances.sortModule |
|
// Grid’s rowDataBound event
rowDataBound: function(args) {
// Row index is returned and assigned to the required cell’s innerText
var rowIndex = parseInt(args.row.getAttribute('aria-rowindex'));
// Here we have assigned it to the first column’s cell
args.row.querySelector('.e-rowcell').innerText = rowIndex;
} |
|
import { GridPlugin, ForeignKey, Page } from "@syncfusion/ej2-vue-grids";
import { data, hierarchyOrderdata, employeeData } from './datasource.js';
Vue.use(GridPlugin);
export default {
name: 'app',
data() {
return {
datasheetColumns: [
{ field: 'OrderID', headerText: 'Order ID', width: 100 },
{ field: 'EmployeeID', headerText: 'Employee Name', foreignKeyValue: 'FirstName', foreignKeyField: 'EmployeeID', dataSource: employeeData, width: 120 },
{ field: 'Freight', headerText: 'Freight', format: 'N2', width: 100 }
],
data: hierarchyOrderdata
}
}
} |
|
// Directly assign the foreign column data to the grid columns based on its index
this.$refs.grid.ej2Instances.columns[1].dataSource = employeeData; |
|
<style>
// CSS class for header cells
.e-headercelldiv {
color: #0066ff;
font-family: cursive;
}
// CSS class for content cells
.e-rowcell {
color: #590c0c !important;
font-family: sans-serif;
}
</style> |
|
<style>
// CSS class for row
.e-row {
background-color: #00ff43;
}
// CSS class for alternate rows
.e-row.e-altrow {
background-color: #00ffff;
}
// CSS class for header
.e-headercell {
background-color: #df239c !important;
}
</style> |
|
<ejs-grid id="grid" ref="gridObj" :dataBound='onDataBound' :dataSource="data" height="315">
<e-columns>
<e-column field='status' headerText="State" :template="checkTemplate" width="80"></e-column>
</e-columns>
</ejs-grid>
export default {
name: 'app',
data() {
return {
checkTemplate: () => {
return {
template: Vue.component("columnTemplate", {
template: `<div v-if=cData class="template_checkbox">
<input type="checkbox" checked />
</div>
<div v-else class="template_checkbox">
<input type="checkbox" />
</div>`,
data: function () {
return {
data: {}
};
},
computed: {
cData: function () {
// Field value is returned based on which checkbox is rendered using v-if and v-else condition
return this.data.status;
}
}
})
};
}
};
},
} |
|
// Grid’s dataBound event function
onDataBound: function(args) {
// Checkbox elements rendered inside the column template are retrieved
var checkboxElements = this.$refs.gridObj.ej2Instances.element.querySelectorAll('.template_checkbox');
var count = 0;
while (count < checkboxElements.length) {
var inputEle = checkboxElements[count].querySelector('input');
// Initialize CheckBox component.
var checkbox = new CheckBox({
// Checked state is set based on input elements state
checked: (inputEle.checked) ? true : false,
change: this.checkboxChange.bind(this)
});
// Render initialized CheckBox
checkbox.appendTo(inputEle);
count++;
}
},
// Checkbox’s change event
checkboxChange: function(args) {
// Checkbox state is retrieved
console.log('Checked state: ' + args.checked);
// Row data is retrieved by passing the checkbox element to Grid’s getRowInfo method
var rowData = this.$refs.gridObj.ej2Instances.getRowInfo(args.event.target);
} |