Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HeuristicLabWeb.PluginHost/HLWebPluginHost/Content/jQuery/jQueryPlugins/DataTables-1.7.6/examples/server_side/select_rows.html @ 6286

Last change on this file since 6286 was 6286, checked in by dkahn, 13 years ago

#1198 Added jQuery plus plugins

File size: 9.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3  <head>
4    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5    <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" />
6   
7    <title>DataTables example</title>
8    <style type="text/css" title="currentStyle">
9      @import "../../media/css/demo_page.css";
10      @import "../../media/css/demo_table.css";
11    </style>
12    <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
13    <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
14    <script type="text/javascript" charset="utf-8">
15var oTable;
16var gaiSelected =  [];
17
18$(document).ready(function() {
19  $('#form').submit( function() {
20    alert (gaiSelected);
21    return false;
22  } );
23
24  /* Init the table */
25  oTable = $("#example").dataTable({
26    "bProcessing": true,
27    "bServerSide": true,
28    "sAjaxSource": "../examples_support/server_processing_id.php",
29    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
30      if ( jQuery.inArray(aData[0], gaiSelected) != -1 )
31      {
32        $(nRow).addClass('row_selected');
33      }
34      return nRow;
35    },
36    "aoColumnDefs": [
37      { "bVisible": 0, "aTargets": [0] }
38    ]
39  });
40 
41  /* Click event handler */
42  $('#example tbody tr').live('click', function () {
43    var aData = oTable.fnGetData( this );
44    var iId = aData[0];
45   
46    if ( jQuery.inArray(iId, gaiSelected) == -1 )
47    {
48      gaiSelected[gaiSelected.length++] = iId;
49    }
50    else
51    {
52      gaiSelected = jQuery.grep(gaiSelected, function(value) {
53        return value != iId;
54      } );
55    }
56   
57    $(this).toggleClass('row_selected');
58  } );
59} );
60    </script>
61  </head>
62  <body id="dt_example">
63    <div id="container">
64      <div class="full_width big">
65        <i>DataTables</i> server-side processing with user selectable rows example
66      </div>
67     
68      <h1>Preamble</h1>
69      <p>When you want to detail with user selectable rows and DataTables, it is relatively simple when using DOM based data - but if using server-side processing, DataTables doesn't retain state over pages / filters etc, leaving this to the server-side instead. As such, you will need to keep a track of which rows a user as selected and mark them as selected on each draw. This is shown in this demo, which uses a unique ID in the first (and hidden) column.</p>
70      <p>Credit for this example belongs with forum member <a href="http://datatables.net/forums/comments.php?DiscussionID=582&page=1#Item_4">iuliandum</a>. Thanks!</p>
71     
72      <h1>Live example</h1>
73      <div id="dynamic">
74<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
75  <thead>
76    <tr>
77      <th width="0%">ID</th>
78      <th width="20%">Rendering engine</th>
79      <th width="25%">Browser</th>
80      <th width="25%">Platform(s)</th>
81      <th width="15%">Engine version</th>
82      <th width="15%">CSS grade</th>
83    </tr>
84  </thead>
85  <tbody>
86    <tr>
87      <td colspan="5" class="dataTables_empty">Loading data from server</td>
88    </tr>
89  </tbody>
90  <tfoot>
91    <tr>
92      <th>ID</th>
93      <th>Rendering engine</th>
94      <th>Browser</th>
95      <th>Platform(s)</th>
96      <th>Engine version</th>
97      <th>CSS grade</th>
98    </tr>
99  </tfoot>
100</table>
101      </div>
102      <div class="spacer"></div>
103     
104     
105      <h1>Initialisation code</h1>
106      <pre>var oTable;
107var gaiSelected =  [];
108
109$(document).ready(function() {
110  $('#form').submit( function() {
111    alert (gaiSelected);
112    return false;
113  } );
114
115  /* Init the table */
116  oTable = $("#example").dataTable({
117    "bProcessing": true,
118    "bServerSide": true,
119    "sAjaxSource": "../examples_support/server_processing_id.php",
120    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
121      if ( jQuery.inArray(aData[0], gaiSelected) != -1 )
122      {
123        $(nRow).addClass('row_selected');
124      }
125      return nRow;
126    },
127    "aoColumns": [
128      { "bVisible": 0, "aTargets": [0] }
129    ]
130  });
131 
132  /* Click event handler */
133  $('#example tbody tr').live('click', function () {
134    var aData = oTable.fnGetData( this );
135    var iId = aData[0];
136   
137    if ( jQuery.inArray(iId, gaiSelected) == -1 )
138    {
139      gaiSelected[gaiSelected.length++] = iId;
140    }
141    else
142    {
143      gaiSelected = jQuery.grep(gaiSelected, function(value) {
144        return value != iId;
145      } );
146    }
147   
148    $(this).toggleClass('row_selected');
149  } );
150} );</pre>
151     
152     
153      <h1>Other examples</h1>
154      <h2>Basic initialisation</h2>
155      <ul>
156        <li><a href="../basic_init/zero_config.html">Zero configuration</a></li>
157        <li><a href="../basic_init/filter_only.html">Feature enablement</a></li>
158        <li><a href="../basic_init/table_sorting.html">Sorting data</a></li>
159        <li><a href="../basic_init/multi_col_sort.html">Multi-column sorting</a></li>
160        <li><a href="../basic_init/multiple_tables.html">Multiple tables</a></li>
161        <li><a href="../basic_init/hidden_columns.html">Hidden columns</a></li>
162        <li><a href="../basic_init/dom.html">DOM positioning</a></li>
163        <li><a href="../basic_init/state_save.html">State saving</a></li>
164        <li><a href="../basic_init/alt_pagination.html">Alternative pagination styles</a></li>
165        <li>Scrolling:
166          <a href="../basic_init/scroll_x.html">Horizontal</a> /
167          <a href="../basic_init/scroll_y.html">Vertical</a> /
168          <a href="../basic_init/scroll_xy.html">Both</a> /
169          <a href="../basic_init/scroll_y_theme.html">Themed</a> /
170          <a href="../basic_init/scroll_y_infinite.html">Infinite</a>
171        </li>
172        <li><a href="../basic_init/language.html">Change language information (internationalisation)</a></li>
173        <li><a href="../basic_init/themes.html">ThemeRoller themes (Smoothness)</a></li>
174      </ul>
175     
176      <h2>Advanced initialisation</h2>
177      <ul>
178        <li><a href="../advanced_init/events_pre_init.html">Events (pre initialisation)</a></li>
179        <li><a href="../advanced_init/events_post_init.html">Events (post initialisation)</a></li>
180        <li><a href="../advanced_init/column_render.html">Column rendering</a></li>
181        <li><a href="../advanced_init/html_sort.html">Sorting without HTML tags</a></li>
182        <li><a href="../advanced_init/dom_multiple_elements.html">Multiple table controls (sDom)</a></li>
183        <li><a href="../advanced_init/length_menu.html">Defining length menu options</a></li>
184        <li><a href="../advanced_init/dom_toolbar.html">Custom toolbar (element) around table</a></li>
185        <li><a href="../advanced_init/highlight.html">Row highlighting with CSS</a></li>
186        <li><a href="../advanced_init/complex_header.html">Column grouping through col/row spans</a></li>
187        <li><a href="../advanced_init/row_grouping.html">Row grouping</a></li>
188        <li><a href="../advanced_init/row_callback.html">Row callback</a></li>
189        <li><a href="../advanced_init/footer_callback.html">Footer callback</a></li>
190        <li><a href="../advanced_init/language_file.html">Change language information from a file (internationalisation)</a></li>
191      </ul>
192     
193      <h2>Data sources</h2>
194      <ul>
195        <li><a href="../data_sources/dom.html">DOM</a></li>
196        <li><a href="../data_sources/js_array.html">Javascript array</a></li>
197        <li><a href="../data_sources/ajax.html">Ajax source</a></li>
198        <li><a href="../data_sources/server_side.html">Server side processing</a></li>
199      </ul>
200     
201      <h2>Server-side processing</h2>
202      <ul>
203        <li><a href="../server_side/server_side.html">Obtain server-side data</a></li>
204        <li><a href="../server_side/custom_vars.html">Add extra HTTP variables</a></li>
205        <li><a href="../server_side/post.html">Use HTTP POST</a></li>
206        <li><a href="../server_side/column_ordering.html">Custom column ordering (in callback data)</a></li>
207        <li><a href="../server_side/pipeline.html">Pipelining data (reduce Ajax calls for paging)</a></li>
208        <li><a href="../server_side/row_details.html">Show and hide details about a particular record</a></li>
209        <li><a href="../server_side/select_rows.html">User selectable rows (multiple rows)</a></li>
210      </ul>
211     
212      <h2>API</h2>
213      <ul>
214        <li><a href="../api/add_row.html">Dynamically add a new row</a></li>
215        <li><a href="../api/multi_filter.html">Individual column filtering (using "input" elements)</a></li>
216        <li><a href="../api/multi_filter_select.html">Individual column filtering (using "select" elements)</a></li>
217        <li><a href="../api/highlight.html">Highlight rows and columns</a></li>
218        <li><a href="../api/row_details.html">Show and hide details about a particular record</a></li>
219        <li><a href="../api/select_row.html">User selectable rows (multiple rows)</a></li>
220        <li><a href="../api/select_single_row.html">User selectable rows (single row) and delete rows</a></li>
221        <li><a href="../api/editable.html">Editable rows (with jEditable)</a></li>
222        <li><a href="../api/form.html">Submit form with elements in table</a></li>
223        <li><a href="../api/counter_column.html">Index column (static number column)</a></li>
224        <li><a href="../api/show_hide.html">Show and hide columns dynamically</a></li>
225        <li><a href="../api/api_in_init.html">API function use in initialisation object (callback)</a></li>
226        <li><a href="../api/tabs_and_scrolling.html">DataTables scrolling and tabs</a></li>
227        <li><a href="../api/regex.html">Regular expression filtering</a></li>
228      </ul>
229     
230      <h2>Plug-ins</h2>
231      <ul>
232        <li><a href="../plug-ins/plugin_api.html">Add custom API functions</a></li>
233        <li><a href="../plug-ins/sorting_plugin.html">Sorting and type detection</a></li>
234        <li><a href="../plug-ins/paging_plugin.html">Custom pagination controls</a></li>
235        <li><a href="../plug-ins/range_filtering.html">Range filtering / custom filtering</a></li>
236        <li><a href="../plug-ins/dom_sort.html">Live DOM sorting</a></li>
237        <li><a href="../plug-ins/html_sort.html">Automatic HTML type detection</a></li>
238      </ul>
239     
240     
241      <p>Please refer to the <a href="http://www.datatables.net/"><i>DataTables</i> documentation</a> for full information about its API properties and methods.</p>
242     
243     
244      <div id="footer" style="text-align:center;">
245        <span style="font-size:10px;">DataTables &copy; Allan Jardine 2008-2010</span>
246      </div>
247    </div>
248  </body>
249</html>
Note: See TracBrowser for help on using the repository browser.