-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTableExample.html
More file actions
188 lines (184 loc) · 6.25 KB
/
Copy pathDataTableExample.html
File metadata and controls
188 lines (184 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Additional field options | AltEditor examples</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.css"
/>
<link
rel="stylesheet"
href="https://cdn.datatables.net/2.3.8/css/dataTables.dataTables.css"
/>
<link
rel="stylesheet"
href="https://cdn.datatables.net/buttons/3.2.6/css/buttons.dataTables.css"
/>
<link
rel="stylesheet"
href="https://cdn.datatables.net/select/3.1.3/css/select.dataTables.css"
/>
<link
rel="stylesheet"
href="https://cdn.datatables.net/responsive/3.0.8/css/responsive.dataTables.css"
/>
<link rel="stylesheet" href="../../dist/dataTables.altEditor.css" />
<link rel="stylesheet" href="../examples.css" />
<script src="../theme.js"></script>
</head>
<body class="examples-page">
<main class="example-main">
<header class="example-header">
<nav aria-label="Example navigation">
<a href="../../index.html">← All examples</a>
· <a href="https://github.com/bensitu/DataTable-AltEditor/blob/develop/example/04_more/DataTableExample.html">Configuration source</a>
· <a href="https://github.com/bensitu/DataTable-AltEditor/blob/develop/docs/examples.md">Example guide</a>
</nav>
<p class="example-eyebrow">DataTable-AltEditor / Example 04</p>
<h1>Additional field options</h1>
<p>
Edit an IPv4 address, an on/off selection, and a single port from 0 to
65535. Addresses must be unique. The hidden row identifier and
read-only field are retained when editing. Refresh restores the
original rows.
</p>
</header>
<div
class="example-table"
tabindex="0"
role="region"
aria-label="Editable table 1"
>
<table class="dataTable display" id="testTableData">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<p id="field-result" role="status">New rows default to off and port 8080. Edit a row to compare readonly and disabled fields in the submitted values.</p>
</main>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdn.datatables.net/2.3.8/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/buttons/3.2.6/js/dataTables.buttons.js"></script>
<script src="https://cdn.datatables.net/select/3.1.3/js/dataTables.select.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.js"></script>
<script src="https://cdn.datatables.net/responsive/3.0.8/js/dataTables.responsive.js"></script>
<script src="../../dist/dataTables.altEditor.js"></script>
<script>
$(document).ready(function () {
var columnDefs = [
{
data: 'DT_RowId',
type: 'hidden',
},
{
title: 'Select example',
data: 'status',
type: 'select',
options: ['on', 'off'],
optionsSortByLabel: true,
value: 'off',
},
{
title: 'Text example',
data: 'ipAddress',
type: 'text',
pattern:
'^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){0,1}$',
hoverMsg: '(Optional) - Ex: 82.84.86.88',
unique: true,
},
{
title: 'Port example',
data: 'port',
value: '8080',
type: 'text',
pattern:
'^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$',
hoverMsg: 'Enter a port from 0 to 65535.',
},
{
title: 'Readonly example',
data: 'read',
type: 'readonly',
value: 'Fixed',
},
{
title: 'Disabled example',
data: 'managed',
defaultContent: 'Application',
value: 'Application',
disabled: true,
},
];
const loadUrl = './example4.json';
var myTable = $('#testTableData').dataTable({
layout: { topStart: 'buttons' },
ajax: loadUrl, //Receiving data from this source.
onAddRow: function (editor, values, success) {
values.DT_RowId =
Math.max(
0,
...editor
.api()
.rows()
.data()
.toArray()
.map(function (row) {
return Number(row.DT_RowId) || 0;
})
) + 1;
success();
},
onEditRow: function (editor, values, success) {
document.querySelector('#field-result').textContent = 'Submitted fields: ' + Object.keys(values).join(', ') + '. The disabled managed field is omitted; the readonly read field is included.';
success();
},
columns: columnDefs, //Columns defined above.
select: 'single',
altEditor: true, //Enable altEditor.
responsive: true, //Enable responsiveness.
buttons: [
{
//All implemented buttons. Do not change name attribute.
text: 'Create',
name: 'add',
},
{
extend: 'selected',
text: 'Edit',
name: 'edit',
},
{
extend: 'selected',
text: 'Delete',
name: 'delete',
},
{
text: 'Refresh',
name: 'refresh',
},
],
});
});
</script>
</body>
</html>