JSFiddle - React, Tailwind, and code Playground
by Oleg Kiriljuk
HTML
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/css/ui.jqgrid.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-en.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/jquery.jqGrid.src.js"></script>
<div class="container">
<table id="categorysummary"></table>
</div>
CSS
/* the next two CSS rules I get from free jqGrid CSS:
https://github.com/free-jqgrid/jqGrid/blob/master/css/ui.jqgrid.css
*/
.ui-jqgrid {
position: relative;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
-ms-touch-action: none;
touch-action: none;
}
.ui-jqgrid > .ui-jqgrid-view {
position: relative;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
left: 0;
top: 0;
padding: 0;
font-size: 11px;
}
JavaScript
var serverResponse = {
"page": "1",
"records": "3",
"rows": [
{ "id": "1", IsActive:'N', CategoryName: "Name 1", "ComboDuration": "83123a" },
{ "id": "2", IsActive:'N', CategoryName: "Name 3", "ComboDuration": "83432a" },
{ "id": "3", IsActive:'N', CategoryName: "Name 2", "ComboDuration": "83566a" }
]
},
$grid = $("#categorysummary");
classToSet = "hidden-xs"; //"hidden-xs", "ui-helper-hidden"
function applyClassesToHeaders(table) {
var columnInfo, iCol, iRow,
htable = $(table.grid.hDiv).find("table.ui-jqgrid-htable")[0],
firstRow = table.rows[0];
colModel = $(table).jqGrid("getGridParam", "colModel");
for (iCol = 0; iCol < colModel.length; iCol++) {
columnInfo = colModel[iCol];
if (columnInfo.classes) {
for (iRow = 0; iRow < htable.rows.length; iRow++) {
$(htable.rows[iRow].cells[iCol]).addClass(columnInfo.classes);
}
$(firstRow.cells[iCol]).addClass(columnInfo.classes);
}
}
}
$grid.jqGrid({
//datatype: "jsonstring",
//datastr: serverResponse,
url: "/echo/json/", // use JSFiddle echo service
datatype: "json",
mtype: "POST", // needed for JSFiddle echo service
postData: {
json: JSON.stringify(serverResponse) // needed for JSFiddle echo service
},
colNames: ["Id", "Active", "Name", "Duration"],
colModel: [
{ name: 'Id', hidden: true },
{ name: 'IsActive', align: 'center', sortable: false},
{ name: 'CategoryName', sortable: false },
{ name: 'ComboDuration', classes: classToSet, align: 'center', sortable: false }
],
jsonReader: {
id: 'Id',
repeatitems: false
},
height: "100%",
width: "100%",
rownumbers: true,
rowNum: 1000,
sortname: 'Id',
caption: 'Categories',
loadComplete: function () {
...