JQuery Grid
Set the columnsreorder property of the jqxGrid.
Author: http://jqwidgets.com
by Hristo Hristov
HTML
<script src="https://jqwidgets.com/public/jqwidgets/jqx-all.js"></script>
<link rel="stylesheet" href="https://jqwidgets.com/public/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="https://jqwidgets.com/public/jqwidgets/styles/jqx.energyblue.css">
<script src="https://jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/generatedata.js"></script>
Drag a column header and drop it to a new position
<div id="jqxgrid"></div>
<input type="button" style="margin: 50px;" id="hide" value="hide" />
<input type="button" style="margin: 50px;" id="show" value="show" />
<button id="getstate">Get State</button>
<button id="save">Save</button>
<button id="load">Load</button>
JavaScript
var data = generatedata(500);
var source = {
localdata: data,
datafields: [{
name: 'firstname',
type: 'string'
}, {
name: 'lastname',
type: 'string'
}, {
name: 'productname',
type: 'string'
}, {
name: 'date',
type: 'date'
}, {
name: 'quantity',
type: 'number'
}, {
name: 'price',
type: 'number'
}],
datatype: "array"
};
var adapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid({
width: 500,
theme: 'energyblue',
source: adapter,
filterable:true,
showfilterrow: true,
columnsreorder: true,
columns: [{
text: 'First Name',
datafield: 'firstname',
pinned:true,
filtertype:'checkedlist',
columngroup: 'Name',
width: 90
}, {
text: 'Last Name',
columngroup: 'Name',
datafield: 'lastname',
width: 90
}, {
text: 'Product',
datafield: 'productname',
width: 170
}, {
text: 'Order Date',
datafield: 'date',
width: 160,
cellsformat: 'dd-MMMM-yyyy'
}, {
text: 'Quantity',
datafield: 'quantity',
width: 80,
cellsalign: 'right'
}, {
text: 'Unit Price',
datafield: 'price',
cellsalign: 'right',
cellsformat: 'c2'
}]
});
$('#show').click(function () {
$("#jqxgrid").jqxGrid('showcolumn', 'firstname');
});
$('#hide').click(function () {
$("#jqxgrid").jqxGrid('hidecolumn', 'firstname');
});
$('#getstate').click(function () {
var finfo = $('#jqxgrid').jqxGrid('getfilterinformation');
console.log('filter info: ');
console.log(finfo.filter.getfilters());
console.log(finfo.datafield);
var state = $('#jqxgrid').jqxGrid('getstate');
console.log('getstate: ');
console.log(state.filters);
});