Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HeuristicLabWeb.PluginHost/HLWebPluginHost/Content/jQuery/jQueryPlugins/DataTables-1.7.6/media/unit_testing/tests_onhold/2_js/fnRowCallback.js @ 6286

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

#1198 Added jQuery plus plugins

File size: 2.2 KB
Line 
1// DATA_TEMPLATE: js_data
2oTest.fnStart( "fnRowCallback" );
3
4/* Note - fnRowCallback MUST return the first arguments (modified or not) */
5
6$(document).ready( function () {
7  /* Check the default */
8  var oTable = $('#example').dataTable( {
9    "aaData": gaaData
10  } );
11  var oSettings = oTable.fnSettings();
12  var mPass;
13 
14  oTest.fnTest(
15    "Default should be null",
16    null,
17    function () { return oSettings.fnRowCallback == null; }
18  );
19 
20 
21  oTest.fnTest(
22    "Four arguments passed",
23    function () {
24      oSession.fnRestore();
25     
26      mPass = -1;
27      $('#example').dataTable( {
28        "aaData": gaaData,
29        "fnRowCallback": function ( nTr ) {
30          mPass = arguments.length;
31          return nTr;
32        }
33      } );
34    },
35    function () { return mPass == 4; }
36  );
37 
38 
39  oTest.fnTest(
40    "fnRowCallback called once for each drawn row",
41    function () {
42      oSession.fnRestore();
43     
44      mPass = 0;
45      $('#example').dataTable( {
46        "aaData": gaaData,
47        "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
48          mPass++;
49          return nTr;
50        }
51      } );
52    },
53    function () { return mPass == 10; }
54  );
55 
56  oTest.fnTest(
57    "fnRowCallback allows us to alter row information",
58    function () {
59      oSession.fnRestore();
60      $('#example').dataTable( {
61        "aaData": gaaData,
62        "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
63          $(nTr).addClass('unit_test');
64          return nTr;
65        }
66      } );
67    },
68    function () { return $('#example tbody tr:eq(1)').hasClass('unit_test'); }
69  );
70 
71  oTest.fnTest(
72    "Data array has length matching columns",
73    function () {
74      oSession.fnRestore();
75     
76      mPass = true;
77      $('#example').dataTable( {
78        "aaData": gaaData,
79        "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
80          if ( asData.length != 5 )
81            mPass = false;
82          return nTr;
83        }
84      } );
85    },
86    function () { return mPass; }
87  );
88 
89  oTest.fnTest(
90    "Data array has length matching columns",
91    function () {
92      oSession.fnRestore();
93     
94      mPass = true;
95      var iCount = 0;
96      $('#example').dataTable( {
97        "aaData": gaaData,
98        "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) {
99          if ( iCount != iDrawIndex )
100            mPass = false;
101          iCount++;
102          return nTr;
103        }
104      } );
105    },
106    function () { return mPass; }
107  );
108 
109 
110 
111  oTest.fnComplete();
112} );
Note: See TracBrowser for help on using the repository browser.