-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample8.js
More file actions
165 lines (162 loc) · 2.85 KB
/
Copy pathexample8.js
File metadata and controls
165 lines (162 loc) · 2.85 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
$(document).ready(function () {
var dataSet = [
[
1,
'Tiger Nixon',
'System Architect',
'Edinburgh',
'5421',
'2011-04-25',
'$320,800',
1,
'1',
],
[
2,
'Garrett Winters',
'Accountant',
'Tokyo',
'8422',
'2011-07-25',
'$170,750',
2,
'2',
],
[
3,
'Ashton Cox',
'Junior Technical Author',
'San Francisco',
'1562',
'2009-01-12',
'$86,000',
3,
'3',
],
[
4,
'Cedric Kelly',
'Senior Javascript Developer',
'Edinburgh',
'6224',
'2012-03-29',
'$433,060',
4,
'4',
],
[
5,
'Airi Satou',
'Accountant',
'Tokyo',
'5407',
'2008-11-28',
'$162,700',
5,
'5',
],
[
6,
'Brielle Williamson',
'Integration Specialist',
'New York',
'4804',
'2012-12-02',
'$372,000',
6,
'6',
],
];
var columnDefs = [
{
title: 'Id',
type: 'readonly',
},
{
title: 'Name',
type: 'text',
required: true,
unique: true,
},
{
title: 'Position',
required: true,
type: 'text',
},
{
title: 'Office',
//no type = text
},
{
title: 'Extn.',
type: 'number',
},
{
title: 'Start date',
type: 'date',
},
{
title: 'Salary',
type: 'text',
pattern: '\\$[1-9][0-9]{0,2}(,[0-9]{3})+',
hoverMsg: 'At least $1,000',
},
{
title: 'Unique number',
type: 'number',
unique: true,
},
{
title: 'Select unique',
type: 'select',
select2: {
allowClear: true,
placeholder: 'Choose an option',
width: '100%',
},
options: ['1', '2', '3', '4', '5', '6', '7', '8'],
unique: true,
},
];
var myTable;
myTable = $('#example').DataTable({
pagingType: 'full_numbers',
data: dataSet,
columns: columnDefs,
onAddRow: function (editor, values, success) {
values[0] =
Math.max(
0,
...editor
.api()
.rows()
.data()
.toArray()
.map(function (row) {
return Number(row[0]) || 0;
})
) + 1;
success();
},
layout: { topStart: 'buttons' },
select: 'single',
responsive: true,
altEditor: true, // Enable altEditor
buttons: [
{
text: 'Add',
name: 'add', // do not change name
},
{
extend: 'selected', // Bind to Selected row
text: 'Edit',
name: 'edit', // do not change name
},
{
extend: 'selected', // Bind to Selected row
text: 'Delete',
name: 'delete', // do not change name
},
],
});
});