Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
<!DOCTYPE html>
2
<html>
3
<head>
4
	<meta charset="utf-8">
5
	<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
6
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
7
 
8
	<title>DataTables example - Retain selection on reload</title>
9
	<link rel="stylesheet" type="text/css" href="../../../../media/css/jquery.dataTables.css">
10
	<link rel="stylesheet" type="text/css" href="../../css/select.dataTables.css">
11
	<link rel="stylesheet" type="text/css" href="../../../Buttons/css/buttons.dataTables.css">
12
	<link rel="stylesheet" type="text/css" href="../../../../examples/resources/syntax/shCore.css">
13
	<link rel="stylesheet" type="text/css" href="../../../../examples/resources/demo.css">
14
	<style type="text/css" class="init">
15
 
16
	</style>
17
	<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
18
	<script type="text/javascript" language="javascript" src="../../../../media/js/jquery.dataTables.js"></script>
19
	<script type="text/javascript" language="javascript" src="../../js/dataTables.select.js"></script>
20
	<script type="text/javascript" language="javascript" src="../../../Buttons/js/dataTables.buttons.js"></script>
21
	<script type="text/javascript" language="javascript" src="../../../../examples/resources/syntax/shCore.js"></script>
22
	<script type="text/javascript" language="javascript" src="../../../../examples/resources/demo.js"></script>
23
	<script type="text/javascript" language="javascript" class="init">
24
 
25
$(document).ready(function() {
26
	var table = $('#example').DataTable( {
27
		ajax: '../../../../examples/ajax/data/objects.txt',
28
		deferRender: true,
29
		columns: [
30
			{ data: 'name' },
31
			{ data: 'position' },
32
			{ data: 'office' },
33
			{ data: 'extn' },
34
			{ data: 'start_date' },
35
			{ data: 'salary' }
36
		],
37
		rowId: 'extn',
38
		select: true,
39
		dom: 'Bfrtip',
40
		buttons: [
41
			{
42
				text: 'Reload table',
43
				action: function () {
44
					table.ajax.reload();
45
				}
46
			}
47
		]
48
	} );
49
} );
50
 
51
	</script>
52
</head>
53
 
54
<body class="dt-example">
55
	<div class="container">
56
		<section>
57
			<h1>DataTables example <span>Retain selection on reload</span></h1>
58
 
59
			<div class="info">
60
				<p>DataTables has the ability to use a property in the data source for each row as that row's unique identifier through the <a href=
61
				"//datatables.net/reference/option/rowId"><code class="option" title="DataTables initialisation option">rowId</code></a> option. This is typically used in
62
				DataTables to assign an <code>id</code> attribute to the <code class="tag" title="HTML tag">tr</code> elements in the table, but it can also be used by Select and
63
				other libraries to retain a unique identifier for each row over data reloads.</p>
64
 
65
				<p>Select uses this information to be able to retain row selection over a data reload. Generally, if a table is reloaded, the state of each row is lost (since the
66
				old rows are deleted and new rows added), but this can be undesirable, particularly if performing frequent data updates. Setting the <a href=
67
				"//datatables.net/reference/option/rowId"><code class="option" title="DataTables initialisation option">rowId</code></a> option of DataTables will address
68
				this.</p>
69
 
70
				<p>This example uses the <code>extn</code> property of the row as the <a href="//datatables.net/reference/option/rowId"><code class="option" title=
71
				"DataTables initialisation option">rowId</code></a> option (normally a database primary key might be used). A reload button is also available through the <a href=
72
				"https://datatables.net/extensions/buttons">Buttons extension</a> which will call the <a href="//datatables.net/reference/api/ajax.reload()"><code class="api"
73
				title="DataTables API method">ajax.reload()</code></a> method when activated.</p>
74
 
75
				<p>To demonstrate Select's ability to retain the selected rows over a data reload, select a number of rows and then click the <em>Reload table</em> button.</p>
76
			</div>
77
 
78
			<table id="example" class="display" cellspacing="0" width="100%">
79
				<thead>
80
					<tr>
81
						<th>Name</th>
82
						<th>Position</th>
83
						<th>Office</th>
84
						<th>Extn.</th>
85
						<th>Start date</th>
86
						<th>Salary</th>
87
					</tr>
88
				</thead>
89
 
90
				<tfoot>
91
					<tr>
92
						<th>Name</th>
93
						<th>Position</th>
94
						<th>Office</th>
95
						<th>Extn.</th>
96
						<th>Start date</th>
97
						<th>Salary</th>
98
					</tr>
99
				</tfoot>
100
			</table>
101
 
102
			<ul class="tabs">
103
				<li class="active">Javascript</li>
104
				<li>HTML</li>
105
				<li>CSS</li>
106
				<li>Ajax</li>
107
				<li>Server-side script</li>
108
			</ul>
109
 
110
			<div class="tabs">
111
				<div class="js">
112
					<p>The Javascript shown below is used to initialise the table shown in this example:</p><code class="multiline language-js">$(document).ready(function() {
113
	var table = $('#example').DataTable( {
114
		ajax: '../../../../examples/ajax/data/objects.txt',
115
		deferRender: true,
116
		columns: [
117
			{ data: 'name' },
118
			{ data: 'position' },
119
			{ data: 'office' },
120
			{ data: 'extn' },
121
			{ data: 'start_date' },
122
			{ data: 'salary' }
123
		],
124
		rowId: 'extn',
125
		select: true,
126
		dom: 'Bfrtip',
127
		buttons: [
128
			{
129
				text: 'Reload table',
130
				action: function () {
131
					table.ajax.reload();
132
				}
133
			}
134
		]
135
	} );
136
} );</code>
137
 
138
					<p>In addition to the above code, the following Javascript library files are loaded for use in this example:</p>
139
 
140
					<ul>
141
						<li><a href="//code.jquery.com/jquery-1.11.3.min.js">//code.jquery.com/jquery-1.11.3.min.js</a></li>
142
						<li><a href="../../../../media/js/jquery.dataTables.js">../../../../media/js/jquery.dataTables.js</a></li>
143
						<li><a href="../../js/dataTables.select.js">../../js/dataTables.select.js</a></li>
144
						<li><a href="../../../Buttons/js/dataTables.buttons.js">../../../Buttons/js/dataTables.buttons.js</a></li>
145
					</ul>
146
				</div>
147
 
148
				<div class="table">
149
					<p>The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:</p>
150
				</div>
151
 
152
				<div class="css">
153
					<div>
154
						<p>This example uses a little bit of additional CSS beyond what is loaded from the library files (below), in order to correctly display the table. The
155
						additional CSS used is shown below:</p><code class="multiline language-css"></code>
156
					</div>
157
 
158
					<p>The following CSS library files are loaded for use in this example to provide the styling of the table:</p>
159
 
160
					<ul>
161
						<li><a href="../../../../media/css/jquery.dataTables.css">../../../../media/css/jquery.dataTables.css</a></li>
162
						<li><a href="../../css/select.dataTables.css">../../css/select.dataTables.css</a></li>
163
						<li><a href="../../../Buttons/css/buttons.dataTables.css">../../../Buttons/css/buttons.dataTables.css</a></li>
164
					</ul>
165
				</div>
166
 
167
				<div class="ajax">
168
					<p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data will update automatically as any additional data is
169
					loaded.</p>
170
				</div>
171
 
172
				<div class="php">
173
					<p>The script used to perform the server-side processing for this table is shown below. Please note that this is just an example script using PHP. Server-side
174
					processing scripts can be written in any language, using <a href="//datatables.net/manual/server-side">the protocol described in the DataTables
175
					documentation</a>.</p>
176
				</div>
177
			</div>
178
		</section>
179
	</div>
180
 
181
	<section>
182
		<div class="footer">
183
			<div class="gradient"></div>
184
 
185
			<div class="liner">
186
				<h2>Other examples</h2>
187
 
188
				<div class="toc">
189
					<div class="toc-group">
190
						<h3><a href="./index.html">Initialisation</a></h3>
191
						<ul class="toc active">
192
							<li><a href="./simple.html">Simple initialisation</a></li>
193
							<li><a href="./single.html">Single item selection</a></li>
194
							<li><a href="./multi.html">Multi item selection</a></li>
195
							<li><a href="./cells.html">Cell selection</a></li>
196
							<li><a href="./checkbox.html">Checkbox selection</a></li>
197
							<li><a href="./i18n.html">Internationalisation</a></li>
198
							<li><a href="./blurable.html">Blur selection</a></li>
199
							<li><a href="./deferRender.html">Defer rendering</a></li>
200
							<li><a href="./buttons.html">Buttons</a></li>
201
							<li class="active"><a href="./reload.html">Retain selection on reload</a></li>
202
						</ul>
203
					</div>
204
 
205
					<div class="toc-group">
206
						<h3><a href="../styling/index.html">Styling</a></h3>
207
						<ul class="toc">
208
							<li><a href="../styling/bootstrap.html">Bootstrap styling</a></li>
209
							<li><a href="../styling/foundation.html">Foundation styling</a></li>
210
							<li><a href="../styling/jqueryui.html">jQuery UI styling</a></li>
211
						</ul>
212
					</div>
213
 
214
					<div class="toc-group">
215
						<h3><a href="../api/index.html">API</a></h3>
216
						<ul class="toc">
217
							<li><a href="../api/events.html">Events</a></li>
218
							<li><a href="../api/get.html">Get selected items</a></li>
219
							<li><a href="../api/select.html">Select items</a></li>
220
						</ul>
221
					</div>
222
				</div>
223
 
224
				<div class="epilogue">
225
					<p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full information about its API properties and methods.<br>
226
					Additionally, there are a wide range of <a href="http://www.datatables.net/extensions">extensions</a> and <a href=
227
					"http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of DataTables.</p>
228
 
229
					<p class="copyright">DataTables designed and created by <a href="http://www.sprymedia.co.uk">SpryMedia Ltd</a> &#169; 2007-2015<br>
230
					DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
231
				</div>
232
			</div>
233
		</div>
234
	</section>
235
</body>
236
</html>