VueJS Grid – Advanced Data Grid Component

VueJS Grid – Advanced Data Grid Component

In this Post We Will Explain About is VueJS Grid – Advanced Data Grid Component With Example and Demo.

Welcome on infinityknow.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Simple Vuejs Grid Component – Vuejs Script

In this post we will show you Best way to implement Data Grid Control – Vuejs Data Grid Component, hear for How to Vue.JS – Advanced Data Grid Component with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  JQuery Ajax Add Remove Input Fields Dynamically

First of simple create a new This is an simple example of new creating a very reusable grid data component data and using simple it with more external dataGrid Component Example.

index.html

[php]

Vue.JS simple table Datagrid

[/php]

Script.js

[php]
Vue.filter(“groupBy”, function(value, key) {
var data_groups = {
data: value
};

if (key) {
data_groups = {};
for (var data_in = 0; data_in < value.length; data_in++) { var row = value[data_in]; var datacell = row[key]; if (!data_groups.hasOwnProperty(datacell)) { data_groups[datacell] = []; } data_groups[datacell].push(row); } } return data_groups; }); Vue.filter("date", function(value, format) { var date = moment(value); if (!date.isValid()) { return value; } return date.format(format); }); Vue.component("dropdown", { template: "#dropdown-template", props: { for: { type: String, required: true }, origin: { type: String, default: "top right" }, preserveState: { type: Boolean, default: false } }, computed: { originClass: function() { switch (this.origin) { case "top left": return "dropdown-top-left"; case "bottom left": return "dropdown-bottom-left"; case "bottom right": return "dropdown-bottom-right"; } } }, data: function() { return { show: false }; }, ready: function() { var _this = this; var element = document.getElementById(_this.for); var hide = function(event) { event.stopPropagation(); if (!(_this.preserveState && _this.$el.contains(event.target))) { _this.show = false; document.body.removeEventListener("click", hide); } }; var show = function(event) { event.preventDefault(); event.stopPropagation(); var dropdowns = [].slice.call(document.querySelectorAll(".dropdown")); dropdowns.forEach(function(dropdown) { dropdown.__vue__.show = false; }); if (!_this.show) { _this.show = true; document.body.addEventListener("click", hide); } }; element.addEventListener("click", show); } }); Vue.component("datagridOptions", { template: "#datagrid-options-template", props: { gridId: { type: String, required: true }, columns: { type: Array, required: true }, data_all_sel: { type: Boolean }, allowEdit: { type: Boolean }, gpcolm: { type: Object, required: true }, dataFilter: { type: String, required: true }, showAdvancedOptions: { type: Boolean } }, methods: { getDatactrlnm(columnKey, datasufix) { return this.gridId + "-" + columnKey + "-" + datasufix; } } }); Vue.component("datagrid", { template: "#datagrid-template", components: ["datagridOptions"], props: { id: { type: String, required: true }, columns: { type: Array, required: true }, data: { type: Array }, datacellTemplate: { type: String, required: false, default: "firstgrid" }, data_all_sel: { type: Boolean, required: false, default: false }, allowEdit: { type: Boolean, required: false, default: false }, showDefaultOptions: { type: Boolean, required: false, default: true }, showAdvancedOptions: { type: Boolean, required: false, default: false } }, computed: { data_colspan: function() { return this.data_all_sel ? this.columns.length + 1 : this.columns.length; }, showOptions: function() { return this.showDefaultOptions || this.showAdvancedOptions; }, showFooter: function() { return this.dataFilter || this.gpcolm || this.myrow.length > 0;
}

},
data: function() {

return {
sortingKey: null,
sortingDirection: 1,
gpcolm: null,
dataFilter: null,
myrow: [],
selectAll: false
};

},
methods: {

getCellTemplate: function(column) {
return this.allowEdit ? “editableGridCell” : (column.template || this.datacellTemplate);
},

getCellWidth: function(column) {
if (!column.width) {
return;
}

return column.width + (isNaN(column.width) ? “” : “%”);
},

getControlId: function(mygpname, index, datasufix) {
return mygpname + “-” + index + (datasufix ? “-” + datasufix : “”);
},

sortBy: function(column) {
if (column.key === this.sortingKey) {
this.sortingDirection *= -1;
return;
}

this.sortingKey = column.key;
this.sortingDirection = 1;
},

groupBy: function(column) {
this.gpcolm = column;
},

resetFilter() {
this.dataFilter = null;
},

total_grouping() {
this.gpcolm = null;
},

resetSelection() {
this.myrow = [];
this.selectAll = false;
},

formatData: function(column, value) {
if (column.hasOwnProperty(“filter”)) {
var filter = Vue.filter(column.filter.name);
var args = [].concat(value, column.filter.args);
return filter.apply(this, args);
}
return value;
}
},
watch: {

“selectAll”: function(value) {
this.myrow = value ? [].concat(this.data) : [];
}

}
});

Vue.partial(“firstgrid”, “{{ formatData(column, row[column.key]) }}“);
Vue.partial(“editableGridCell”, ““);
Vue.partial(“linkedGridCell”, ““);

var vue = new Vue({
el: “#index”,
data: {
employeer: {
columns: [{
key: “user_fname”,
name: “Given Name”,
template: “linkedGridCell”
}, {
key: “user_lastname”,
name: “user_lastname”
}, {
key: “useremail”,
name: “useremail”,
width: 33
}, {
key: “date_birth”,
name: “Date of Birth”,
filter: {
name: “date”,
args: [“DD MMMM YYYY”]
}
}],
data: [{
“ID”: 0,
“user_fname”: “John”,
“user_lastname”: “drhitesh”,
“date_birth”: “1986-10-03T00:00:00”,
“useremail”: “john.dipak@dipaksteel.com”,
“posttitle”: “Co-Founder and CEO”,
“office”: “drhitesh Steel Pty Ltd”
}, {
“ID”: 1,
“user_fname”: “Jane”,
“user_lastname”: “drhitesh”,
“date_birth”: “1988-05-28T00:00:00”,
“useremail”: “jane.dipak@dipaksteel.com”,
“posttitle”: “Co-Founder and CEO”,
“office”: “drhitesh Steel Pty Ltd”
}, {
“ID”: 2,
“user_fname”: “Richard”,
“user_lastname”: “Swanston”,
“date_birth”: “1972-08-15T00:00:00”,
“useremail”: “rswanston@telco.com”,
“posttitle”: “Purchasing manager”,
“office”: “Cortana Mining Co”
}, {
“ID”: 3,
“user_fname”: “Robert”,
“user_lastname”: “Brown”,
“date_birth”: “1968-01-18T00:00:00”,
“useremail”: “robbrown@othertelco.com”,
“posttitle”: “Sales Manager”,
“office”: “Powerhouse Marketing”
}, {
“ID”: 4,
“user_fname”: “Phillip”,
“user_lastname”: “Zucco”,
“date_birth”: “2018-06-28T00:00:00”,
“useremail”: “phil.zucco@workplace.com”,
“posttitle”: “Applications Developer”,
“office”: “Workplace Pty Ltd”
}, {
“ID”: 5,
“user_fname”: “arti”,
“user_lastname”: “arti”,
“date_birth”: “2018-07-27T00:00:00”,
“useremail”: “james.caldwell@mayur.com”,
“posttitle”: “arti manager”,
“office”: “mayur Industries Ltd.”
}, {
“ID”: 6,
“user_fname”: “dwplak”,
“user_lastname”: “O’Reilly”,
“date_birth”: “2018-08-15T00:00:00”,
“useremail”: “roreilly@energy.com”,
“posttitle”: “Workplace Health and Safety manager”,
“office”: “lorial office”
}]
}
}
});
[/php]

Example

I hope you have Got TreeGrid: Vuejs table, grid, tree view or Gantt chart And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Leave a Comment