2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
27 <script type="text/javascript">
30 function getElementClass(element) {
31 return $(element).attr('class') || '';
34 // fetch the occurrence of element
35 function getRowId(row, str) {
37 $.each(row, function(i, n) {
38 if (str === $(n).attr('class')) {
45 // for date sorting see http://wiki.civicrm.org/confluence/display/CRMDOC/Sorting+Date+Fields+in+dataTables+Widget
46 var useAjax = {/literal}{if $useAjax}1{else}0{/if}{literal};
48 var useClass = 'display';
52 {/literal}{if isset($sourceUrl)}sourceUrl = "{$sourceUrl}";{/if}{literal}
53 useClass = 'pagerDisplay';
57 var tableId = [], count = 1;
59 //rename id of table with sequence
60 //and create the object for navigation
61 $('table.' + useClass).each(function() {
62 $(this).attr('id','option' + tcount + count);
67 $.each(tableId, function(i,n){
68 var tabId = '#option' + tcount + n;
69 //get the object of first tr data row.
70 var tdObject = $(tabId + ' tr:nth(1) td');
71 var id = -1; var count = 0; var columns=''; var sortColumn = '';
72 //build columns array for sorting or not sorting
73 $(tabId + ' th').each( function( ) {
74 var option = $(this).prop('id').split("_");
75 option = ( option.length > 1 ) ? option[1] : option[0];
76 var stype = 'numeric';
79 sortColumn += '[' + count + ', "asc" ],';
80 columns += '{"sClass": "'+ getElementClass( this ) +'"},';
85 if ( $(this).attr('class') == 'sortable' ){
86 sortColumn += '[' + count + ', "asc" ],';
88 var sortId = getRowId(tdObject, $(this).attr('id') +' hiddenElement' );
89 columns += '{ "render": function ( data, type, row ) { return "<div style=\'display:none\'>"+ data +"</div>" + row[sortId] ; }, "targets": sortColumn,"bUseRendered": false},';
92 columns += '{ "bSortable": false, "sClass": "'+ getElementClass( this ) +'"},';
95 columns += '{ "sType": "currency" },';
98 columns += '{"sType": "html"},';
101 if ( $(this).text() ) {
102 columns += '{"sClass": "'+ getElementClass( this ) +'"},';
104 columns += '{ "bSortable": false },';
110 // Fixme: this could be done without eval
111 columns = columns.substring(0, columns.length - 1 );
112 sortColumn = sortColumn.substring(0, sortColumn.length - 1 );
113 eval('sortColumn =[' + sortColumn + ']');
114 eval('columns =[' + columns + ']');
116 var currTable = $(tabId);
118 // contains the dataTables master records
119 var s = $(document).dataTableSettings;
120 if (s != 'undefined') {
122 for (var i=0; i < len; i++) {
123 // if already exists, remove from the array
124 if (s[i].sInstance = tabId) {
131 var noRecordFoundMsg = {/literal}'{ts escape="js"}There are no records.{/ts}'{literal};
135 oTable = $(tabId).dataTable({
138 "aaSorting": sortColumn,
139 "aoColumns": columns,
142 "asStripClasses": [ "odd-row", "even-row" ],
143 "sPaginationType": "full_numbers",
144 "sDom": '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
146 "sAjaxSource": sourceUrl,
148 "sEmptyTable": noRecordFoundMsg,
149 "sZeroRecords": noRecordFoundMsg
151 "fnServerData": function ( sSource, aoData, fnCallback ) {
157 "success": fnCallback
162 oTable = $(tabId).dataTable({
163 "aaSorting": sortColumn,
165 "bLengthChange": true,
168 "asStripClasses": [ "odd-row", "even-row" ],
170 "aoColumns": columns,
173 "sEmptyTable": noRecordFoundMsg,
174 "sZeroRecords": noRecordFoundMsg
181 //plugin to sort on currency
182 cj.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
183 var symbol = "{/literal}{$config->defaultCurrencySymbol($config->defaultSymbol)}{literal}";
184 var x = (a == "-") ? 0 : a.replace( symbol, "" );
185 var y = (b == "-") ? 0 : b.replace( symbol, "" );
188 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
191 cj.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
192 var symbol = "{/literal}{$config->defaultCurrencySymbol($config->defaultSymbol)}{literal}";
193 var x = (a == "-") ? 0 : a.replace( symbol, "" );
194 var y = (b == "-") ? 0 : b.replace( symbol, "" );
197 return ((x < y) ? 1 : ((x > y) ? -1 : 0));