Vue.component("grid-component",
{
template: "#grid-template",
props: {
columns: Array,
data: {
type: Array,
default: function() { return [] }
},
filterParams: Object,
initData: Boolean,
lengthMenu: {
type: Array,
default: function () { return [5, 10, 25, 50] }
},
ordering: Boolean,
serverSide: Boolean,
url: String
},
data: function () {
var sortOrders = {}
this.columns.forEach(function (column) { // get sort order
sortOrders[column.name] = 1;
});
// return v2 data props
return {
currentPage: 1,
perpage: 5, // length of the per page
searchQuery: "",
sortKey: "",
sortOrders: sortOrders,
serverSideData: [],
totalRecords: 0
};
},
components: {
Pagination
},
computed: {
filteredData: function () { // computes data to be shown in the grid.
const vm = this;
// if the table is serverside processing then return back the filtered data...
// sorting and paging happens in the server side.
if (vm.serverSide)
return vm.filterRecords();
// this statements will be executed when data is eager loaded...
let data = vm.filterRecords();
const sortKey = vm.sortKey;
const order = vm.sortOrders[sortKey] || 1;
if (sortKey) {
data = data.slice().sort(function (a, b) {
a = a[sortKey];
b = b[sortKey];
return (a === b ? 0 : a > b ? 1 : -1) * order;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.