ax5ui-grid
Version:
A grid plugin that works with Bootstrap & jQuery
219 lines (199 loc) • 9.34 kB
HTML
<!--
~ Copyright (c) 2017. tom@axisj.com
~ - github.com/thomasjang
~ - www.axisj.com
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>GRID</title>
<link rel="stylesheet" type="text/css" href="bower_components/bootstrap/dist/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="../../ax5ui-mask/dist/ax5mask.css"/>
<link rel="stylesheet" type="text/css" href="../../ax5ui-calendar/dist/ax5calendar.css"/>
<link rel="stylesheet" type="text/css" href="../../ax5ui-picker/dist/ax5picker.css"/>
<link rel="stylesheet" type="text/css" href="../../ax5ui-select/dist/ax5select.css"/>
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../dist/ax5grid.css"/>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="../../ax5core/dist/ax5core.js"></script>
<script src="../../ax5ui-formatter/dist/ax5formatter.min.js"></script>
<script src="../../ax5ui-calendar/dist/ax5calendar.min.js"></script>
<script src="../../ax5ui-picker/dist/ax5picker.min.js"></script>
<script src="../../ax5ui-select/dist/ax5select.js"></script>
<script src="../dist/ax5grid.js"></script>
</head>
<body style="padding: 20px;">
<div style="border:1px solid #0a68b4;position: relative;height:400px;" id="grid-parent">
<div data-ax5grid="first-grid" data-ax5grid-config='{name:"my first grid"}' style="height: 100%;"></div>
</div>
<style>
</style>
<div style="height: 10px;"></div>
<TEXTAREA ID="holdtext" STYLE="position:absolute;top:-1000px;"></TEXTAREA>
<script>
ax5.ui.grid.tmpl.page_status = function(){
return '<span>{{{progress}}} {{fromRowIndex}} - {{toRowIndex}} of {{dataRowCount}} {{#totalElements}} Total {{.}}{{/totalElements}}</span>';
};
ax5.ui.grid.tmpl.page_status = function(){
return '<span>{{{progress}}} {{fromRowIndex_page}} - {{toRowIndex_page}} of {{totalElements}}</span>';
};
var sampleData = [
{a: "A", b: "A01", price: 1000, amount: 12, saleDt: "2016-08-29", customer: "장기영", userType: "M"},
{a: "A", b: "A02", price: 1100, amount: 11, saleDt: "2016-08-28", customer: "장서우", userType: "D"},
{a: "A", b: "A03", price: 1200, amount: 10, saleDt: "2016-08-27", customer: "이영희", userType: "W"},
{a: "B", b: "B01", price: 1300, amount: 8, saleDt: "2016-08-25", customer: "황인서", userType: "M"},
{a: "B", b: "B02", price: 1400, amount: 5, saleDt: "2016-08-29", customer: "황세진", userType: "S"},
{a: "B", b: "B03", price: 1500, amount: 2, saleDt: "2016-08-26", customer: "이서연", userType: "W"}
];
var gridView = {
initView: function () {
this.target = new ax5.ui.grid();
this.target.setConfig({
target: $('[data-ax5grid="first-grid"]'),
frozenColumnIndex: 2,
frozenRowIndex: 0,
showLineNumber: true,
showRowSelector: true,
multipleSelect: true,
lineNumberColumnWidth: 40,
rowSelectorColumnWidth: 28,
sortable: true, // 모든 컬럼에 정렬 아이콘 표시
multiSort: false, // 다중 정렬 여부
remoteSort: false, // remoteSort에 함수를 sortable 컬럼이 클릭되었을때 실행 setColumnSort를 직접 구현. (remoteSort를 사용하면 헤더에 정렬 상태만 표시 하고 데이터 정렬은 처리 안함)
header: {
align: "center",
columnHeight: 28
},
body: {
align: "center",
columnHeight: 28,
onClick: function () {
// console.log(this);
this.self.select(this.dindex);
}
},
page: {
navigationItemCount: 9,
height: 30,
display: true,
firstIcon: '<i class="fa fa-step-backward" aria-hidden="true"></i>',
prevIcon: '<i class="fa fa-caret-left" aria-hidden="true"></i>',
nextIcon: '<i class="fa fa-caret-right" aria-hidden="true"></i>',
lastIcon: '<i class="fa fa-step-forward" aria-hidden="true"></i>',
onChange: function () {
gridView.setData(this.page.selectPage);
}
},
columns: [
{
key: "a",
label: "필드A",
width: 80,
styleClass: function () {
return "ABC";
},
enableFilter: true,
align: "center",
editor: {
type: "text", disabled: function () {
// item, value
return false;
}
}
},
{key: "b", label: "필드B", align: "center", editor: {type: "text"}},
{
key: undefined,
label: "필드C", columns: [
{key: "price", label: "단가", align: "right", formatter: "money", editor: {type: "money", updateWith: ['cost']}},
{key: "amount", label: "수량", align: "right", formatter: "money", editor: {type: "number", updateWith: ['cost']}},
{
key: "cost", label: "금액", align: "right", formatter: function () {
return ax5.util.number(this.item.price * this.item.amount, {"money": true});
}
}
]
},
{
key: "saleDt", label: "판매일자", align: "center", editor: {
type: "date", config: {}
}
},
{
key: "saleType", label: "판매타입", editor: {
type: "select", config: {
columnKeys: {
optionValue: "CD", optionText: "NM"
},
options: [
{CD: "A", NM: "A: String"},
{CD: "B", NM: "B: Number"},
{CD: "C", NM: "C: substr"},
{CD: "D", NM: "D: substring"}
]
}
}
},
{
key: "isChecked", label: "체크박스", width: 50, sortable: false, editor: {
type: "checkbox", config: {height: 17, trueValue: "Y", falseValue: "N"}
}
},
{
key: "customer", label: "고객명", editor: {type: "text"}
}
],
footSum: [
[
{label: "전체 합계", colspan: 2, align: "center"},
{key: "price", collector: "avg", formatter: "money", align: "right"},
{key: "amount", collector: "sum", formatter: "money", align: "right"},
{
key: "cost", collector: function () {
var value = 0;
this.list.forEach(function (n) {
if (!n.__isGrouping) value += (n.price * n.amount);
});
return ax5.util.number(value, {"money": 1});
}, align: "right"
}
]]
});
return this;
},
setData: function (_pageNo) {
var list = [];
var pageSize = 11;
if(_pageNo == 4){
for (var i = 0, l = 4; i < l; i++) {
list.push($.extend({}, sampleData[(Math.floor(Math.random() * sampleData.length))]));
}
}
else{
for (var i = 0, l = pageSize; i < l; i++) {
list.push($.extend({}, sampleData[(Math.floor(Math.random() * sampleData.length))]));
}
}
this.target.setData({
list: list,
page: {
currentPage: _pageNo || 0,
pageSize: pageSize,
totalElements: 48,
totalPages: 5
}
});
return this;
}
};
$(document.body).ready(function () {
gridView
.initView()
.setData();
});
</script>
</body>
</html>