//@translator codepiano
23//@email codepiano.li@gmail.com
4//尝试着翻译了一下,难免有错误的地方,欢迎发邮件告知,多谢。
5
6$(document).ready( function (){
7 $('selector').dataTable( {
8
12 "bAutoWidth":true,
13
18 "bDeferRender":false,
19
25 "bFilter":true,
26
30 "bInfo":true,
31
35 "bJQueryUI":false,
36
40 "bLengthChange":false,
41
45 "bPaginage":true,
46
51 "bProcessing":false,
52
57 "bScrollInfinite":false,
58
62 "bServerSide":false,
63
67 "bSort":true,
68
74 "bSortClasses":true,
75
80 "bStateSave":false,
81
86 "sScrollX":"100%",
87
92 "sScrollY":"100%",
93
96 "oLanguage":{
97 "oAria":{
98
102 "sSortAscending": " - click/return to sort ascending",
103
107 "sSortDescending": " - click/return to sort descending"
108 },
109 "oPaginate": {
110
114 "sFirst": "First page",
115
119 "sLast": "Last page",
120
124 "sNext": "Next page",
125
129 "sPrevious": "Previous page"
130 },
131
136 "sEmptyTable": "No data available in table",
137
141 "sInfo": "Got a total of _TOTAL_ entries to show (_START_ to _END_)",
142
146 "sInfoEmpty": "No entries to show",
147
151 "sInfoFiltered": " - filtering from _MAX_ records",
152
157 "sInfoPostFix": "All records shown are derived from real information.",
158
163 "sInfoThousands": "'",
164
169 "sLengthMenu": "Display _MENU_ records",
170
175 "sLoadingRecords": "Please wait - loading...",
176
180 "sProcessing": "DataTables is currently busy",
181
187 "sSearch": "Apply filter _INPUT_ to table",
188
194 "sUrl": 195
200 "sZeroRecords": "No records to display"
201 }
202 });
203});
204
205
206
212$('selector').dataTable({
213 "bFilter": false,
214 "bDestroy": true
215});
216
217
224$(document).ready(function(){
225 initTable();
226 tableActions();
227});
228
229function initTable()
230{
231 return $('#example').dataTable( {
232 "sScrollY": "200px",
233 "bPaginate": false,
234 "bRetrieve": true
235 });
236}
237
238function tableActions()
239{
240 var oTable = initTable();
241 // perform API operations with oTable
242}
243
244
249$(document).ready(function(){
250 $('#example').dataTable( {
251 "bScrollAutoCss": false,
252 "sScrollY": "200px"
253 });
254});
255
256
263$(document).ready(function(){
264 $('#example').dataTable( {
265 "sScrollY": "200",
266 "bScrollCollapse": true
267 });
268});
269
270
275$(document).ready(function(){
276 $('#example').dataTable( {
277 "bSortCellsTop": true
278 });
279});
280
281
286$(document).ready(function(){
287 $('#example').dataTable( {
288 "iCookieDuration": 60*60*24 // 1 day
289 });
290})
291
292
299$(document).ready(function(){
300 $('#example').dataTable( {
301 "bServerSide": true,
302 "sAjaxSource": "scripts/server_processing.php",
303 "iDeferLoading": 57
304 });
305});
306
307
312$(document).ready(function(){
313 $('#example').dataTable( {
314 "bServerSide": true,
315 "sAjaxSource": "scripts/server_processing.php",
316 "iDeferLoading": 57
317 });
318});
319
320
326$(document).ready(function(){
327 $('#example').dataTable( {
328 "iDisplayStart": 20
329 });
330})
331
332
338$(document).ready(function(){
339 $('#example').dataTable( {
340 "bScrollInfinite": true,
341 "bScrollCollapse": true,
342 "sScrollY": "200px",
343 "iScrollLoadGap": 50
344 });
345});
346
347
354$(document).ready(function(){
355 $('#example').dataTable( {
356 "iTabIndex": 1
357 });
358});
359
360
367$(document).ready(function(){
368 $('#example').dataTable( {
369 "oSearch": {"sSearch": "Initial search"}
370 });
371})
372
373
379// Get data from { "data": [...] }
380$(document).ready(function(){
381 var oTable = $('#example').dataTable( {
382 "sAjaxSource": "sources/data.txt",
383 "sAjaxDataProp": "data"
384 });
385});
386
387// Get data from { "data": { "inner": [...] } }
388$(document).ready(function(){
389 var oTable = $('#example').dataTable( {
390 "sAjaxSource": "sources/data.txt",
391 "sAjaxDataProp": "data.inner"
392 });
393});
394
395
401$(document).ready(function(){
402 $('#example').dataTable( {
403 "sAjaxSource": 404 });
405})
406
407
412$(document).ready(function(){
413 $('#example').dataTable( {
414 "sCookiePrefix": "my_datatable_",
415 });
416});
417
418
441$(document).ready(function(){
442 $('#example').dataTable( {
443 "sDom": 'rt
444 });
445});
446
447
453$(document).ready(function(){
454 $('#example').dataTable( {
455 "sPaginationType": "full_numbers"
456 });
457})
458
459
466$(document).ready(function(){
467 $('#example').dataTable( {
468 "sScrollX": "100%",
469 "sScrollXInner": "110%"
470 });
471});
472
473
478$(document).ready(function(){
479 $('#example').dataTable({
480 "bServerSide": true,
481 "sAjaxSource": "scripts/post.php",
482 "sServerMethod": "POST"
483 });
484});
485
486
492$(document).ready(function (){
493 $('#example').dataTable({
494 "fnCookieCallback": function (sName, oData, sExpires, sPath) {
495 // Customise oData or sName or whatever else here
496 return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
497 }
498 });
499});
500
501
507$(document).ready(function(){
508 $('#example').dataTable({
509 "fnCreatedRow": function( nRow, aData, iDataIndex ){
510 // Bold the grade for all 'A' grade browsers
511 if ( aData[4] == "A" )
512 {
513 $('td:eq(4)', nRow).html( 'A' );
514 }
515 }
516 });
517});
518
519
524$(document).ready( function(){
525 $('#example').dataTable({
526 "fnDrawCallback": function(){
527 alert( 'DataTables has redrawn the table' );
528 }
529 });
530});
531
532
537$(document).ready( function(){
538 $('#example').dataTable({
539 "fnDrawCallback": function() {
540 alert( 'DataTables has redrawn the table' );
541 }
542 });
543});
544
545
552$(document).ready(function(){
553 $('#example').dataTable({
554 "fnFormatNumber": function ( iIn ) {
555 if ( iIn < 1000 ) {
556 return iIn;
557 } else {
558 var
559 s=(iIn+""),
560 a=s.split(""), out="",
561 iLen=s.length;
562
563 for ( var i=0 ; i{
564 if ( i%3 === 0 && i !== 0 ) {
565 out = "'"+out;
566 }
567 out = a[iLen-i-1]+out;
568 }
569 }
570 return out;
571 };
572 });
573});
574
575
580$(document).ready(function(){
581 $('#example').dataTable({
582 "fnFormatNumber": function ( iIn ) {
583 if ( iIn < 1000 ) {
584 return iIn;
585 } else {
586 var
587 s=(iIn+""),
588 a=s.split(""), out="",
589 iLen=s.length;
590
591 for ( var i=0 ; i{
592 if ( i%3 === 0 && i !== 0 ) {
593 out = "'"+out;
594 }
595 out = a[iLen-i-1]+out;
596 }
597 }
598 return out;
599 };
600 });
601});
602
603
609$('#example').dataTable( {
610 "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
611 return iStart +" to "+ iEnd;
612 }
613});
614
615
621$(document).ready( function(){
622 $('#example').dataTable({
623 "fnInitComplete": function(oSettings, json) {
624 alert( 'DataTables has finished its initialisation.' );
625 }
626 });
627})
628
629
635$(document).ready( function(){
636 $('#example').dataTable({
637 "fnPreDrawCallback": function( oSettings ) {
638 if ( $('#test').val() == 1 ) {
639 return false;
640 }
641 }
642 });
643});
644
645
651$(document).ready(function(){
652 $('#example').dataTable({
653 "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
654 // Bold the grade for all 'A' grade browsers
655 if ( aData[4] == "A" )
656 {
657 $('td:eq(4)', nRow).html( 'A' );
658 }
659 }
660 });
661});
662
663
669// POST data to server
670$(document).ready(function(){
671 $('#example').dataTable( {
672 "bProcessing": true,
673 "bServerSide": true,
674 "sAjaxSource": "xhr.php",
675 "fnServerData": function ( sSource, aoData, fnCallback ) {
676 $.ajax( {
677 "dataType": 'json',
678 "type": "POST",
679 "url": sSource,
680 "data": aoData,
681 "success": fnCallback
682 } );
683 }
684 });
685});
686
687
693$(document).ready(function(){
694 $('#example').dataTable( {
695 "bProcessing": true,
696 "bServerSide": true,
697 "sAjaxSource": "scripts/server_processing.php",
698 "fnServerParams": function ( aoData ) {
699 aoData.push( { "name": "more_data", "value": "my_value" } );
700 }
701 });
702});
703
704
710$(document).ready(function(){
711 $('#example').dataTable({
712 "bStateSave": true,
713 "fnStateSave": function (oSettings, oData) {
714 var o;
715
716 // Send an Ajax request to the server to get the data. Note that
717 // this is a synchronous request.
718 $.ajax( {
719 "url": "/state_load",
720 "async": false,
721 "dataType": "json",
722 "success": function (json) {
723 o = json;
724 }
725 } );
726 return o;
727 }
728 });
729});
730
731
738// Remove a saved filter, so filtering is never loaded
739$(document).ready(function(){
740 $('#example').dataTable({
741 "bStateSave": true,
742 "fnStateLoadParams": function (oSettings, oData) {
743 oData.oFilter.sSearch = "";
744 });
745 });
746
747
748// Disallow state loading by returning false
749$(document).ready(function(){
750 $('#example').dataTable({
751 "bStateSave": true,
752 "fnStateLoadParams": function (oSettings, oData) {
753 return false;
754 });
755 });
756
757
762// Show an alert with the filtering value that was saved
763$(document).ready(function(){
764 $('#example').dataTable({
765 "bStateSave": true,
766 "fnStateLoaded": function (oSettings, oData) {
767 alert( 'Saved filter was: '+oData.oFilter.sSearch );
768 });
769 });
770
771
777$(document).ready(function(){
778 $('#example').dataTable({
779 "bStateSave": true,
780 "fnStateSave": function (oSettings, oData) {
781 // Send an Ajax request to the server with the state object
782 $.ajax( {
783 "url": "/state_save",
784 "data": oData,
785 "dataType": "json",
786 "method": "POST"
787 "success": function () {}
788 });
789 }
790 });
791});
792
793
799// Remove a saved filter, so filtering is never saved
800$(document).ready(function(){
801 $('#example').dataTable({
802 "bStateSave": true,
803 "fnStateLoadParams": function (oSettings, oData) {
804 oData.oFilter.sSearch = "";
805 });
806 });
807
808
813// Using aoColumnDefs
814$(document).ready(function(){
815 $('#example').dataTable({
816 "aoColumnDefs": [
817 { "aDataSort": [ 0, 1 ], "aTargets": [ 0 ] },
818 { "aDataSort": [ 1, 0 ], "aTargets": [ 1 ] },
819 { "aDataSort": [ 2, 3, 4 ], "aTargets": [ 2 ] }
820 ]
821 });
822});
823
824
825// Using aoColumns
826$(document).ready(function(){
827 $('#example').dataTable({
828 "aoColumns": [
829 { "aDataSort": [ 0, 1 ] },
830 { "aDataSort": [ 1, 0 ] },
831 { "aDataSort": [ 2, 3, 4 ] },
832 null,
833 null
834 ]
835 });
836});
837
838
843// Using aoColumnDefs
844$(document).ready(function(){
845 $('#example').dataTable({
846 "aoColumnDefs": [
847 { "asSorting": [ "asc" ], "aTargets": [ 1 ] },
848 { "asSorting": [ "desc", "asc", "asc" ], "aTargets": [ 2 ] },
849 { "asSorting": [ "desc" ], "aTargets": [ 3 ] }
850 ]
851 });
852});
853
854
855// Using aoColumns
856$(document).ready(function(){
857 $('#example').dataTable( {
858 "aoColumns": [
859 null,
860 { "asSorting": [ "asc" ] },
861 { "asSorting": [ "desc", "asc", "asc" ] },
862 { "asSorting": [ "desc" ] },
863 null
864 ]
865 });
866});
867
868
873// Using aoColumnDefs
874$(document).ready(function(){
875 $('#example').dataTable({
876 "aoColumnDefs": [
877 { "bSearchable": false, "aTargets": [ 0 ] }
878 ]} );
879});
880
881
882// Using aoColumns
883$(document).ready(function(){
884 $('#example').dataTable({
885 "aoColumns": [
886 { "bSearchable": false },
887 null,
888 null,
889 null,
890 null
891 ] });
892});
893
894
899// Using aoColumnDefs
900$(document).ready(function(){
901 $('#example').dataTable({
902 "aoColumnDefs": [
903 { "bSortable": false, "aTargets": [ 0 ] }
904 ] });
905});
906
907
908// Using aoColumns
909$(document).ready(function(){
910 $('#example').dataTable( {
911 "aoColumns": [
912 { "bSortable": false },
913 null,
914 null,
915 null,
916 null
917 ] });
918});
919
920
926// Using aoColumnDefs
927$(document).ready(function() {
928 $('#example').dataTable( {
929 "aoColumnDefs": [
930 {
931 "fnRender": function ( oObj ) {
932 return oObj.aData[0] +' '+ oObj.aData[3];
933 },
934 "bUseRendered": false,
935 "aTargets": [ 0 ]
936 }
937 ]
938 } );
939} );
940
941// Using aoColumns
942$(document).ready(function() {
943 $('#example').dataTable( {
944 "aoColumns": [
945 {
946 "fnRender": function ( oObj ) {
947 return oObj.aData[0] +' '+ oObj.aData[3];
948 },
949 "bUseRendered": false
950 },
951 null,
952 null,
953 null,
954 null
955 ]
956 } );
957} );
958
959
964// Using aoColumnDefs
965$(document).ready(function() {
966 $('#example').dataTable( {
967 "aoColumnDefs": [
968 { "bVisible": false, "aTargets": [ 0 ] }
969 ] } );
970} );
971
972
973// Using aoColumns
974$(document).ready(function() {
975 $('#example').dataTable( {
976 "aoColumns": [
977 { "bVisible": false },
978 null,
979 null,
980 null,
981 null
982 ] } );
983} );
984
985
991$(document).ready(function() {
992 $('#example').dataTable( {
993 "aoColumnDefs": [ {
994 "aTargets": [3],
995 "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
996 if ( sData == "1.7" ) {
997 $(nTd).css('color', 'blue')
998 }
999 }
1000 } ]
1001 });
1002} );
1003
1004/*