[6286] | 1 | // DATA_TEMPLATE: empty_table |
---|
| 2 | oTest.fnStart( "aoColumns.fnRender" ); |
---|
| 3 | |
---|
| 4 | $(document).ready( function () { |
---|
| 5 | /* Check the default */ |
---|
| 6 | var mTmp = 0; |
---|
| 7 | var oTable = $('#example').dataTable( { |
---|
| 8 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 9 | "aoColumns": [ |
---|
| 10 | null, |
---|
| 11 | { "fnRender": function (a) { |
---|
| 12 | mTmp++; |
---|
| 13 | return a.aData[a.iDataColumn]; |
---|
| 14 | } }, |
---|
| 15 | null, |
---|
| 16 | null, |
---|
| 17 | null |
---|
| 18 | ] |
---|
| 19 | } ); |
---|
| 20 | var oSettings = oTable.fnSettings(); |
---|
| 21 | |
---|
| 22 | oTest.fnWaitTest( |
---|
| 23 | "Single column - fnRender is called once for each row", |
---|
| 24 | null, |
---|
| 25 | function () { return mTmp == 57; } |
---|
| 26 | ); |
---|
| 27 | |
---|
| 28 | oTest.fnWaitTest( |
---|
| 29 | "Confirm that fnRender passes one argument (an object) with three parameters", |
---|
| 30 | function () { |
---|
| 31 | mTmp = true; |
---|
| 32 | oSession.fnRestore(); |
---|
| 33 | oTable = $('#example').dataTable( { |
---|
| 34 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 35 | "aoColumns": [ |
---|
| 36 | null, |
---|
| 37 | { "fnRender": function (a) { |
---|
| 38 | if ( arguments.length != 1 || typeof a.iDataRow=='undefined' || |
---|
| 39 | typeof a.iDataColumn=='undefined' || typeof a.aData=='undefined' ) |
---|
| 40 | { |
---|
| 41 | mTmp = false; |
---|
| 42 | } |
---|
| 43 | return a.aData[a.iDataColumn]; |
---|
| 44 | } }, |
---|
| 45 | null, |
---|
| 46 | null, |
---|
| 47 | null |
---|
| 48 | ] |
---|
| 49 | } ); |
---|
| 50 | }, |
---|
| 51 | function () { return mTmp; } |
---|
| 52 | ); |
---|
| 53 | |
---|
| 54 | oTest.fnWaitTest( |
---|
| 55 | "fnRender iDataColumn is row number", |
---|
| 56 | function () { |
---|
| 57 | var iCount = 0; |
---|
| 58 | mTmp = true; |
---|
| 59 | oSession.fnRestore(); |
---|
| 60 | oTable = $('#example').dataTable( { |
---|
| 61 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 62 | "aoColumns": [ |
---|
| 63 | null, |
---|
| 64 | { "fnRender": function (a) { |
---|
| 65 | if ( iCount != a.iDataRow ) |
---|
| 66 | { |
---|
| 67 | mTmp = false; |
---|
| 68 | } |
---|
| 69 | iCount++; |
---|
| 70 | return a.aData[a.iDataColumn]; |
---|
| 71 | } }, |
---|
| 72 | null, |
---|
| 73 | null, |
---|
| 74 | null |
---|
| 75 | ] |
---|
| 76 | } ); |
---|
| 77 | }, |
---|
| 78 | function () { return mTmp; } |
---|
| 79 | ); |
---|
| 80 | |
---|
| 81 | oTest.fnWaitTest( |
---|
| 82 | "fnRender iDataColumn is the column", |
---|
| 83 | function () { |
---|
| 84 | mTmp = true; |
---|
| 85 | oSession.fnRestore(); |
---|
| 86 | oTable = $('#example').dataTable( { |
---|
| 87 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 88 | "aoColumns": [ |
---|
| 89 | null, |
---|
| 90 | { "fnRender": function (a) { |
---|
| 91 | if ( a.iDataColumn != 1 ) |
---|
| 92 | { |
---|
| 93 | mTmp = false; |
---|
| 94 | } |
---|
| 95 | return a.aData[a.iDataColumn]; |
---|
| 96 | } }, |
---|
| 97 | null, |
---|
| 98 | null, |
---|
| 99 | null |
---|
| 100 | ] |
---|
| 101 | } ); |
---|
| 102 | }, |
---|
| 103 | function () { return mTmp; } |
---|
| 104 | ); |
---|
| 105 | |
---|
| 106 | oTest.fnWaitTest( |
---|
| 107 | "fnRender aData is data array of correct size", |
---|
| 108 | function () { |
---|
| 109 | mTmp = true; |
---|
| 110 | oSession.fnRestore(); |
---|
| 111 | oTable = $('#example').dataTable( { |
---|
| 112 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 113 | "aoColumns": [ |
---|
| 114 | null, |
---|
| 115 | { "fnRender": function (a) { |
---|
| 116 | if ( a.aData.length != 5 ) |
---|
| 117 | { |
---|
| 118 | mTmp = false; |
---|
| 119 | } |
---|
| 120 | return a.aData[a.iDataColumn]; |
---|
| 121 | } }, |
---|
| 122 | null, |
---|
| 123 | null, |
---|
| 124 | null |
---|
| 125 | ] |
---|
| 126 | } ); |
---|
| 127 | }, |
---|
| 128 | function () { return mTmp; } |
---|
| 129 | ); |
---|
| 130 | |
---|
| 131 | oTest.fnWaitTest( |
---|
| 132 | "Passed back data is put into the DOM", |
---|
| 133 | function () { |
---|
| 134 | oSession.fnRestore(); |
---|
| 135 | oTable = $('#example').dataTable( { |
---|
| 136 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 137 | "aoColumns": [ |
---|
| 138 | null, |
---|
| 139 | { "fnRender": function (a) { |
---|
| 140 | return 'unittest'; |
---|
| 141 | } }, |
---|
| 142 | null, |
---|
| 143 | null, |
---|
| 144 | null |
---|
| 145 | ] |
---|
| 146 | } ); |
---|
| 147 | }, |
---|
| 148 | function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'unittest'; } |
---|
| 149 | ); |
---|
| 150 | |
---|
| 151 | oTest.fnWaitTest( |
---|
| 152 | "Passed back data is put into the DOM", |
---|
| 153 | function () { |
---|
| 154 | oSession.fnRestore(); |
---|
| 155 | oTable = $('#example').dataTable( { |
---|
| 156 | "sAjaxSource": "../../../examples/examples_support/json_source.txt", |
---|
| 157 | "aoColumns": [ |
---|
| 158 | null, |
---|
| 159 | null, |
---|
| 160 | { "fnRender": function (a) { |
---|
| 161 | return 'unittest1'; |
---|
| 162 | } }, |
---|
| 163 | { "fnRender": function (a) { |
---|
| 164 | return 'unittest2'; |
---|
| 165 | } }, |
---|
| 166 | null |
---|
| 167 | ] |
---|
| 168 | } ); |
---|
| 169 | }, |
---|
| 170 | function () { |
---|
| 171 | var bReturn = |
---|
| 172 | $('#example tbody tr:eq(0) td:eq(2)').html() == 'unittest1' && |
---|
| 173 | $('#example tbody tr:eq(0) td:eq(3)').html() == 'unittest2'; |
---|
| 174 | return bReturn; } |
---|
| 175 | ); |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | oTest.fnComplete(); |
---|
| 182 | } ); |
---|