code
stringlengths
1
2.08M
language
stringclasses
1 value
/********************************************************************* clase Arista * una arista esta compuesta por la union de 2 nodos ********************************************************************/ function hidarista(ide, tipo, idnodoinicio, idnodofin, nombrearista, tipoptomon) { //atributos de la arista this.ide = ide; this.tipo = tipo; this.idnodoinicio = idnodoinicio; this.idnodofin = idnodofin; this.nodoinicio = new hidcomponente(); this.nodofin = new hidcomponente(); this.nombrearista = nombrearista; this.tipoptomon = tipoptomon; this.hidari_find = hidari_find; } //funcion para encontrar las aristas conectadas a un marcador function hidari_find(arraylineas, marcador) { var atributosLinea = {"latitudorigen":0, "longitudorigen":1, "latitudfin":2, "longitudfin":3, "ideorigen":6, "idefin":7}; var lista = []; for (var i = 0; i < arraylineas.length; i++) { if(isNaN(marcador.ide)) { if(arraylineas[i][atributosLinea.latitudorigen] == marcador.posicionactual.lat() && arraylineas[i][atributosLinea.latitudorigen] == marcador.posicionactual.lng()) { var punto = []; punto.push(i); punto.push(0); lista.push(punto); } if(arraylineas[i][atributosLinea.latitudfin] == marcador.posicionactual.lat() && arraylineas[i][atributosLinea.longitudfin] == marcador.posicionactual.lng()) { var punto = []; punto.push(i); punto.push(1); lista.push(punto); } } else { if(arraylineas[i][atributosLinea.ideorigen] == marcador.ide || arraylineas[i][atributosLinea.ideorigen] == marcador.ideparcial) { var punto = []; punto.push(i); punto.push(0); lista.push(punto); } if(arraylineas[i][atributosLinea.idefin] == marcador.ide || arraylineas[i][atributosLinea.idefin] == marcador.ideparcial) { var punto = []; punto.push(i); punto.push(1); lista.push(punto); } } } return lista; }
JavaScript
/********************************************************************* clase Componente * un componente tiene asociado un nodo y un punto de monitoreo ********************************************************************/ function hidcomponente(ide, tipo, tipouni, latitud, longitud, nombre, tipoptomon) { this.ide = ide; this.tipo = tipo; this.latitud = latitud; this.longitud = longitud; this.tipouni = tipouni; this.nombre = nombre; this.tipoptomon = tipoptomon; this.hidcomp_latmayor = hidcomp_latmayor; this.hidcomp_latmenor = hidcomp_latmenor; this.hidcomp_lngmayor = hidcomp_lngmayor; this.hidcomp_lngmenor = hidcomp_lngmenor; this.hidcomp_latarray = hidcomp_latarray; this.hidcomp_lngarray = hidcomp_lngarray; this.hidcomp_tiparray = hidcomp_tiparray; this.hidcomp_idearray = hidcomp_idearray; this.hidcomp_nombarray = hidcomp_nombarray; this.hidcomp_tipoptomonarray = hidcomp_tipoptomonarray; this.hidcomp_find = hidcomp_find; this.hidcomp_findById = hidcomp_findById; this.hidcomp_findByLatLng = hidcomp_findByLatLng; this.hidcomp_numElem = hidcomp_numElem; this.hidcomp_nuevoIde = hidcomp_nuevoIde; } //metodo para obtener la latitud maxima de los componentes function hidcomp_latmayor(compArray) { var mayor = -9999999999999999; for (var i = 0; i < compArray.length; i++) { if(compArray[i].latitud > mayor) { mayor = compArray[i].latitud; } } return mayor; } //metodo para obtener la latitud minima de los componentes function hidcomp_latmenor(compArray) { var menor = 9999999999999999; for (var i = 0; i < compArray.length; i++) { if(compArray[i].latitud < menor) { menor = compArray[i].latitud; } } return menor; } //metodo para obtener la longitud maxima de los componentes function hidcomp_lngmayor(compArray) { var mayor = -9999999999999999; for (var i = 0; i < compArray.length; i++) { if(compArray[i].longitud > mayor) { mayor = compArray[i].longitud; } } return mayor; } //metodo para obtener la longitud minima de los componentes function hidcomp_lngmenor(compArray) { var menor = 9999999999999999; for (var i = 0; i < compArray.length; i++) { if(compArray[i].longitud < menor) { menor = compArray[i].longitud; } } return menor; } //metodo para obtener un arreglo que contenga todas las latitudes function hidcomp_latarray(compArray) { var latarray = []; for(var i = 0; i < compArray.length; i++) { latarray.push(compArray[i].latitud); } return latarray; } //metodo para obtener un arreglo que contenga todas las longitudes function hidcomp_lngarray(compArray) { var lngarray = []; for(var i = 0; i < compArray.length; i++) { lngarray.push(compArray[i].longitud); } return lngarray; } //metodo para obtener un arreglo que contenga todos los nombres de los componentes function hidcomp_nombarray(compArray) { var nombarray = []; for(var i = 0; i < compArray.length; i++) { nombarray.push(compArray[i].nombre); } return nombarray; } //metodo para obtener un arreglo que contenga todos los tipos de punto de monitoreo de los componentes function hidcomp_tipoptomonarray(compArray) { var nombarray = []; for(var i = 0; i < compArray.length; i++) { nombarray.push(compArray[i].tipoptomon); } return nombarray; } //metodo para obtener un arreglo que contenga todos los tipos de los componentes function hidcomp_tiparray(compArray) { var tipoarray = []; for(var i = 0; i < compArray.length; i++) { tipoarray.push(compArray[i].tipo); } return tipoarray; } //metodo para obtener un arreglo que contenga todos los ids de los componentes function hidcomp_idearray(compArray) { var idearray = []; for(var i = 0; i < compArray.length; i++) { idearray.push(compArray[i].ide); } return idearray; } //metodo para obtener el ide de un componente correspondiente a un marcador function hidcomp_find(compArray, marker) { for(var i = 0; i < compArray.length; i++) { var myLatlng = new google.maps.LatLng(compArray[i].latitud,compArray[i].longitud); if(myLatlng.equals(marker.getPosition()) == true) { if(compArray[i].ide != 0) { return compArray[i].ide; } } } return -1; } //metodo para buscar un componente por su ide, retorna la posicion dentro del arreglo de componentes function hidcomp_findById(compArray, ide) { for(var i = 0; i < compArray.length; i++) { if(parseInt(compArray[i].ide) == ide) { return i; } } return -1; } //metodo para buscar un componente por su latitud y longitud, retorna la posicion dentro del arreglo de componentes function hidcomp_findByLatLng(compArray, marker) { for(var i = 0; i < compArray.length; i++) { var myLatlng = new google.maps.LatLng(compArray[i].latitud,compArray[i].longitud); if(myLatlng.equals(marker.getPosition()) == true) { return i; } } return -1; } //metodo para obtener el numero de elementos de un arreglo function hidcomp_numElem(compArray) { return compArray.length; } //metodo para obtener un nuevo ide para un nuevo componente //se verifican un arreglo de componentes y un arreglo de lineas function hidcomp_nuevoIde(compArray, compArray2) { var contador = 0; if(compArray.length > 0 || compArray2.length > 0) { for(var i = 0; i < compArray.length; i++) { if(compArray[i].ide > contador) { contador = compArray[i].ide; } } for(var j = 0; j < compArray2.length; j++) { if(compArray2[j][5] > contador) { contador = compArray2[j][5]; } } return parseInt(contador) + 1; } return parseInt(contador); }
JavaScript
(function() { var showingNav = true; $(document).ready( function () { var jqNav = $('div.fw_nav'); jqNav.css('right', ($(window).width() - $('div.fw_container').width()) /2); var n = $('div.nav_blocker')[0]; n.style.height = $(jqNav).outerHeight()+"px"; n.style.width = ($(jqNav).outerWidth()+20)+"px"; SyntaxHighlighter.highlight(); $('#private_toggle').click( function () { if ( $('input[name=show_private]').val() == 0 ) { $('input[name=show_private]').val( 1 ); $('#private_label').html('Showing'); $('.private').css('display', 'block'); } else { $('input[name=show_private]').val( 0 ); $('#private_label').html('Hiding'); $('.private').css('display', 'none'); } fnWriteCookie(); return false; } ); $('#extended_toggle').click( function () { if ( $('input[name=show_extended]').val() == 0 ) { $('input[name=show_extended]').val( 1 ); $('#extended_label').html('Showing'); $('.augmented').css('display', 'block'); } else { $('input[name=show_extended]').val( 0 ); $('#extended_label').html('Hiding'); $('.augmented').css('display', 'none'); } fnWriteCookie(); return false; } ); var savedHeight = $(jqNav).height(); $('div.fw_nav h2').click( function () { if ( showingNav ) { $('div.fw_nav').animate( { "height": 10, "opacity": 0.3 } ); showingNav = false; } else { $('div.fw_nav').animate( { "height": savedHeight, "opacity": 1 } ); showingNav = true; } fnWriteCookie(); } ); var cookie = fnReadCookie( 'SpryMedia_JSDoc' ); if ( cookie != null ) { var a = cookie.split('-'); if ( a[0] == 1 ) { $('#private_toggle').click(); } if ( a[1] == 0 ) { $('#extended_toggle').click(); } if ( a[2] == 'false' ) { $('div.fw_nav').css('height', 10).css('opacity', 0.3); showingNav = false; } } } ); function fnWriteCookie() { var sVal = $('input[name=show_private]').val()+'-'+ $('input[name=show_extended]').val()+'-'+ showingNav; fnCreateCookie( 'SpryMedia_JSDoc', sVal ); } function fnCreateCookie( sName, sValue ) { var iDays = 365; var date = new Date(); date.setTime( date.getTime()+(iDays*24*60*60*1000) ); var sExpires = "; expires="+date.toGMTString(); document.cookie = sName+"="+sValue+sExpires+"; path=/"; } function fnReadCookie( sName ) { var sNameEQ = sName + "="; var sCookieContents = document.cookie.split(';'); for( var i=0 ; i<sCookieContents.length ; i++ ) { var c = sCookieContents[i]; while (c.charAt(0)==' ') { c = c.substring(1,c.length); } if (c.indexOf(sNameEQ) == 0) { return c.substring(sNameEQ.length,c.length); } } return null; } })();
JavaScript
/* * jQuery Tooltip plugin 1.3 * * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ * http://docs.jquery.com/Plugins/Tooltip * * Copyright (c) 2006 - 2008 Jörn Zaefferer * * $Id: jquery.tooltip.js 5741 2008-06-21 15:22:16Z joern.zaefferer $ * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ ;(function($) { // the tooltip element var helper = {}, // the current tooltipped element current, // the title of the current element, used for restoring title, // timeout id for delayed tooltips tID, // IE 5.5 or 6 IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent), // flag for mouse tracking track = false; $.tooltip = { blocked: false, defaults: { delay: 200, fade: false, showURL: true, extraClass: "", top: 15, left: 15, id: "tooltip" }, block: function() { $.tooltip.blocked = !$.tooltip.blocked; } }; $.fn.extend({ tooltip: function(settings) { settings = $.extend({}, $.tooltip.defaults, settings); createHelper(settings); return this.each(function() { $.data(this, "tooltip", settings); this.tOpacity = helper.parent.css("opacity"); // copy tooltip into its own expando and remove the title this.tooltipText = this.title; $(this).removeAttr("title"); // also remove alt attribute to prevent default tooltip in IE this.alt = ""; }) .mouseover(save) .mouseout(hide) .click(hide); }, fixPNG: IE ? function() { return this.each(function () { var image = $(this).css('backgroundImage'); if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) { image = RegExp.$1; $(this).css({ 'backgroundImage': 'none', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" }).each(function () { var position = $(this).css('position'); if (position != 'absolute' && position != 'relative') $(this).css('position', 'relative'); }); } }); } : function() { return this; }, unfixPNG: IE ? function() { return this.each(function () { $(this).css({'filter': '', backgroundImage: ''}); }); } : function() { return this; }, hideWhenEmpty: function() { return this.each(function() { $(this)[ $(this).html() ? "show" : "hide" ](); }); }, url: function() { return this.attr('href') || this.attr('src'); } }); function createHelper(settings) { // there can be only one tooltip helper if( helper.parent ) return; // create the helper, h3 for title, div for url helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>') // add to document .appendTo(document.body) // hide it at first .hide(); // apply bgiframe if available if ( $.fn.bgiframe ) helper.parent.bgiframe(); // save references to title and url elements helper.title = $('h3', helper.parent); helper.body = $('div.body', helper.parent); helper.url = $('div.url', helper.parent); } function settings(element) { return $.data(element, "tooltip"); } // main event handler to start showing tooltips function handle(event) { // show helper, either with timeout or on instant if( settings(this).delay ) tID = setTimeout(show, settings(this).delay); else show(); // if selected, update the helper position when the mouse moves track = !!settings(this).track; $(document.body).bind('mousemove', update); // update at least once update(event); } // save elements title before the tooltip is displayed function save() { // if this is the current source, or it has no title (occurs with click event), stop if ( $.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler) ) return; // save current current = this; title = this.tooltipText; if ( settings(this).bodyHandler ) { helper.title.hide(); var bodyContent = settings(this).bodyHandler.call(this); if (bodyContent.nodeType || bodyContent.jquery) { helper.body.empty().append(bodyContent) } else { helper.body.html( bodyContent ); } helper.body.show(); } else if ( settings(this).showBody ) { var parts = title.split(settings(this).showBody); helper.title.html(parts.shift()).show(); helper.body.empty(); for(var i = 0, part; (part = parts[i]); i++) { if(i > 0) helper.body.append("<br/>"); helper.body.append(part); } helper.body.hideWhenEmpty(); } else { helper.title.html(title).show(); helper.body.hide(); } // if element has href or src, add and show it, otherwise hide it if( settings(this).showURL && $(this).url() ) helper.url.html( $(this).url().replace('http://', '') ).show(); else helper.url.hide(); // add an optional class for this tip helper.parent.addClass(settings(this).extraClass); // fix PNG background for IE if (settings(this).fixPNG ) helper.parent.fixPNG(); handle.apply(this, arguments); } // delete timeout and show helper function show() { tID = null; if ((!IE || !$.fn.bgiframe) && settings(current).fade) { if (helper.parent.is(":animated")) helper.parent.stop().show().fadeTo(settings(current).fade, current.tOpacity); else helper.parent.is(':visible') ? helper.parent.fadeTo(settings(current).fade, current.tOpacity) : helper.parent.fadeIn(settings(current).fade); } else { helper.parent.show(); } update(); } /** * callback for mousemove * updates the helper position * removes itself when no current element */ function update(event) { if($.tooltip.blocked) return; if (event && event.target.tagName == "OPTION") { return; } // stop updating when tracking is disabled and the tooltip is visible if ( !track && helper.parent.is(":visible")) { $(document.body).unbind('mousemove', update) } // if no current element is available, remove this listener if( current == null ) { $(document.body).unbind('mousemove', update); return; } // remove position helper classes helper.parent.removeClass("viewport-right").removeClass("viewport-bottom"); var left = helper.parent[0].offsetLeft; var top = helper.parent[0].offsetTop; if (event) { // position the helper 15 pixel to bottom right, starting from mouse position left = event.pageX + settings(current).left; top = event.pageY + settings(current).top; var right='auto'; if (settings(current).positionLeft) { right = $(window).width() - left; left = 'auto'; } helper.parent.css({ left: left, right: right, top: top }); } var v = viewport(), h = helper.parent[0]; // check horizontal position if (v.x + v.cx < h.offsetLeft + h.offsetWidth) { left -= h.offsetWidth + 20 + settings(current).left; helper.parent.css({left: left + 'px'}).addClass("viewport-right"); } // check vertical position if (v.y + v.cy < h.offsetTop + h.offsetHeight) { top -= h.offsetHeight + 20 + settings(current).top; helper.parent.css({top: top + 'px'}).addClass("viewport-bottom"); } } function viewport() { return { x: $(window).scrollLeft(), y: $(window).scrollTop(), cx: $(window).width(), cy: $(window).height() }; } // hide helper and restore added classes and the title function hide(event) { if($.tooltip.blocked) return; // clear timeout if possible if(tID) clearTimeout(tID); // no more current element current = null; var tsettings = settings(this); function complete() { helper.parent.removeClass( tsettings.extraClass ).hide().css("opacity", ""); } if ((!IE || !$.fn.bgiframe) && tsettings.fade) { if (helper.parent.is(':animated')) helper.parent.stop().fadeTo(tsettings.fade, 0, complete); else helper.parent.stop().fadeOut(tsettings.fade, complete); } else complete(); if( settings(this).fixPNG ) helper.parent.unfixPNG(); } })(jQuery);
JavaScript
/* * Jeditable - jQuery in place edit plugin * * Copyright (c) 2006-2009 Mika Tuupola, Dylan Verheul * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * * Project home: * http://www.appelsiini.net/projects/jeditable * * Based on editable by Dylan Verheul <dylan_at_dyve.net>: * http://www.dyve.net/jquery/?editable * */ /** * Version 1.7.1 * * ** means there is basic unit tests for this parameter. * * @name Jeditable * @type jQuery * @param String target (POST) URL or function to send edited content to ** * @param Hash options additional options * @param String options[method] method to use to send edited content (POST or PUT) ** * @param Function options[callback] Function to run after submitting edited content ** * @param String options[name] POST parameter name of edited content * @param String options[id] POST parameter name of edited div id * @param Hash options[submitdata] Extra parameters to send when submitting edited content. * @param String options[type] text, textarea or select (or any 3rd party input type) ** * @param Integer options[rows] number of rows if using textarea ** * @param Integer options[cols] number of columns if using textarea ** * @param Mixed options[height] 'auto', 'none' or height in pixels ** * @param Mixed options[width] 'auto', 'none' or width in pixels ** * @param String options[loadurl] URL to fetch input content before editing ** * @param String options[loadtype] Request type for load url. Should be GET or POST. * @param String options[loadtext] Text to display while loading external content. * @param Mixed options[loaddata] Extra parameters to pass when fetching content before editing. * @param Mixed options[data] Or content given as paramameter. String or function.** * @param String options[indicator] indicator html to show when saving * @param String options[tooltip] optional tooltip text via title attribute ** * @param String options[event] jQuery event such as 'click' of 'dblclick' ** * @param String options[submit] submit button value, empty means no button ** * @param String options[cancel] cancel button value, empty means no button ** * @param String options[cssclass] CSS class to apply to input form. 'inherit' to copy from parent. ** * @param String options[style] Style to apply to input form 'inherit' to copy from parent. ** * @param String options[select] true or false, when true text is highlighted ?? * @param String options[placeholder] Placeholder text or html to insert when element is empty. ** * @param String options[onblur] 'cancel', 'submit', 'ignore' or function ?? * * @param Function options[onsubmit] function(settings, original) { ... } called before submit * @param Function options[onreset] function(settings, original) { ... } called before reset * @param Function options[onerror] function(settings, original, xhr) { ... } called on error * * @param Hash options[ajaxoptions] jQuery Ajax options. See docs.jquery.com. * */ (function($) { $.fn.editable = function(target, options) { if ('disable' == target) { $(this).data('disabled.editable', true); return; } if ('enable' == target) { $(this).data('disabled.editable', false); return; } if ('destroy' == target) { $(this) .unbind($(this).data('event.editable')) .removeData('disabled.editable') .removeData('event.editable'); return; } var settings = $.extend({}, $.fn.editable.defaults, {target:target}, options); /* setup some functions */ var plugin = $.editable.types[settings.type].plugin || function() { }; var submit = $.editable.types[settings.type].submit || function() { }; var buttons = $.editable.types[settings.type].buttons || $.editable.types['defaults'].buttons; var content = $.editable.types[settings.type].content || $.editable.types['defaults'].content; var element = $.editable.types[settings.type].element || $.editable.types['defaults'].element; var reset = $.editable.types[settings.type].reset || $.editable.types['defaults'].reset; var callback = settings.callback || function() { }; var onedit = settings.onedit || function() { }; var onsubmit = settings.onsubmit || function() { }; var onreset = settings.onreset || function() { }; var onerror = settings.onerror || reset; /* show tooltip */ if (settings.tooltip) { $(this).attr('title', settings.tooltip); } settings.autowidth = 'auto' == settings.width; settings.autoheight = 'auto' == settings.height; return this.each(function() { /* save this to self because this changes when scope changes */ var self = this; /* inlined block elements lose their width and height after first edit */ /* save them for later use as workaround */ var savedwidth = $(self).width(); var savedheight = $(self).height(); /* save so it can be later used by $.editable('destroy') */ $(this).data('event.editable', settings.event); /* if element is empty add something clickable (if requested) */ if (!$.trim($(this).html())) { $(this).html(settings.placeholder); } $(this).bind(settings.event, function(e) { /* abort if disabled for this element */ if (true === $(this).data('disabled.editable')) { return; } /* prevent throwing an exeption if edit field is clicked again */ if (self.editing) { return; } /* abort if onedit hook returns false */ if (false === onedit.apply(this, [settings, self])) { return; } /* prevent default action and bubbling */ e.preventDefault(); e.stopPropagation(); /* remove tooltip */ if (settings.tooltip) { $(self).removeAttr('title'); } /* figure out how wide and tall we are, saved width and height */ /* are workaround for http://dev.jquery.com/ticket/2190 */ if (0 == $(self).width()) { //$(self).css('visibility', 'hidden'); settings.width = savedwidth; settings.height = savedheight; } else { if (settings.width != 'none') { settings.width = settings.autowidth ? $(self).width() : settings.width; } if (settings.height != 'none') { settings.height = settings.autoheight ? $(self).height() : settings.height; } } //$(this).css('visibility', ''); /* remove placeholder text, replace is here because of IE */ if ($(this).html().toLowerCase().replace(/(;|")/g, '') == settings.placeholder.toLowerCase().replace(/(;|")/g, '')) { $(this).html(''); } self.editing = true; self.revert = $(self).html(); $(self).html(''); /* create the form object */ var form = $('<form />'); /* apply css or style or both */ if (settings.cssclass) { if ('inherit' == settings.cssclass) { form.attr('class', $(self).attr('class')); } else { form.attr('class', settings.cssclass); } } if (settings.style) { if ('inherit' == settings.style) { form.attr('style', $(self).attr('style')); /* IE needs the second line or display wont be inherited */ form.css('display', $(self).css('display')); } else { form.attr('style', settings.style); } } /* add main input element to form and store it in input */ var input = element.apply(form, [settings, self]); /* set input content via POST, GET, given data or existing value */ var input_content; if (settings.loadurl) { var t = setTimeout(function() { input.disabled = true; content.apply(form, [settings.loadtext, settings, self]); }, 100); var loaddata = {}; loaddata[settings.id] = self.id; if ($.isFunction(settings.loaddata)) { $.extend(loaddata, settings.loaddata.apply(self, [self.revert, settings])); } else { $.extend(loaddata, settings.loaddata); } $.ajax({ type : settings.loadtype, url : settings.loadurl, data : loaddata, async : false, success: function(result) { window.clearTimeout(t); input_content = result; input.disabled = false; } }); } else if (settings.data) { input_content = settings.data; if ($.isFunction(settings.data)) { input_content = settings.data.apply(self, [self.revert, settings]); } } else { input_content = self.revert; } content.apply(form, [input_content, settings, self]); input.attr('name', settings.name); /* add buttons to the form */ buttons.apply(form, [settings, self]); /* add created form to self */ $(self).append(form); /* attach 3rd party plugin if requested */ plugin.apply(form, [settings, self]); /* focus to first visible form element */ $(':input:visible:enabled:first', form).focus(); /* highlight input contents when requested */ if (settings.select) { input.select(); } /* discard changes if pressing esc */ input.keydown(function(e) { if (e.keyCode == 27) { e.preventDefault(); //self.reset(); reset.apply(form, [settings, self]); } }); /* discard, submit or nothing with changes when clicking outside */ /* do nothing is usable when navigating with tab */ var t; if ('cancel' == settings.onblur) { input.blur(function(e) { /* prevent canceling if submit was clicked */ t = setTimeout(function() { reset.apply(form, [settings, self]); }, 500); }); } else if ('submit' == settings.onblur) { input.blur(function(e) { /* prevent double submit if submit was clicked */ t = setTimeout(function() { form.submit(); }, 200); }); } else if ($.isFunction(settings.onblur)) { input.blur(function(e) { settings.onblur.apply(self, [input.val(), settings]); }); } else { input.blur(function(e) { /* TODO: maybe something here */ }); } form.submit(function(e) { if (t) { clearTimeout(t); } /* do no submit */ e.preventDefault(); /* call before submit hook. */ /* if it returns false abort submitting */ if (false !== onsubmit.apply(form, [settings, self])) { /* custom inputs call before submit hook. */ /* if it returns false abort submitting */ if (false !== submit.apply(form, [settings, self])) { /* check if given target is function */ if ($.isFunction(settings.target)) { var str = settings.target.apply(self, [input.val(), settings]); $(self).html(str); self.editing = false; callback.apply(self, [self.innerHTML, settings]); /* TODO: this is not dry */ if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } } else { /* add edited content and id of edited element to POST */ var submitdata = {}; submitdata[settings.name] = input.val(); submitdata[settings.id] = self.id; /* add extra data to be POST:ed */ if ($.isFunction(settings.submitdata)) { $.extend(submitdata, settings.submitdata.apply(self, [self.revert, settings])); } else { $.extend(submitdata, settings.submitdata); } /* quick and dirty PUT support */ if ('PUT' == settings.method) { submitdata['_method'] = 'put'; } /* show the saving indicator */ $(self).html(settings.indicator); /* defaults for ajaxoptions */ var ajaxoptions = { type : 'POST', data : submitdata, dataType: 'html', url : settings.target, success : function(result, status) { if (ajaxoptions.dataType == 'html') { $(self).html(result); } self.editing = false; callback.apply(self, [result, settings]); if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } }, error : function(xhr, status, error) { onerror.apply(form, [settings, self, xhr]); } }; /* override with what is given in settings.ajaxoptions */ $.extend(ajaxoptions, settings.ajaxoptions); $.ajax(ajaxoptions); } } } /* show tooltip again */ $(self).attr('title', settings.tooltip); return false; }); }); /* privileged methods */ this.reset = function(form) { /* prevent calling reset twice when blurring */ if (this.editing) { /* before reset hook, if it returns false abort reseting */ if (false !== onreset.apply(form, [settings, self])) { $(self).html(self.revert); self.editing = false; if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } /* show tooltip again */ if (settings.tooltip) { $(self).attr('title', settings.tooltip); } } } }; }); }; $.editable = { types: { defaults: { element : function(settings, original) { var input = $('<input type="hidden"></input>'); $(this).append(input); return(input); }, content : function(string, settings, original) { $(':input:first', this).val(string); }, reset : function(settings, original) { original.reset(this); }, buttons : function(settings, original) { var form = this; if (settings.submit) { /* if given html string use that */ if (settings.submit.match(/>$/)) { var submit = $(settings.submit).click(function() { if (submit.attr("type") != "submit") { form.submit(); } }); /* otherwise use button with given string as text */ } else { var submit = $('<button type="submit" />'); submit.html(settings.submit); } $(this).append(submit); } if (settings.cancel) { /* if given html string use that */ if (settings.cancel.match(/>$/)) { var cancel = $(settings.cancel); /* otherwise use button with given string as text */ } else { var cancel = $('<button type="cancel" />'); cancel.html(settings.cancel); } $(this).append(cancel); $(cancel).click(function(event) { //original.reset(); if ($.isFunction($.editable.types[settings.type].reset)) { var reset = $.editable.types[settings.type].reset; } else { var reset = $.editable.types['defaults'].reset; } reset.apply(form, [settings, original]); return false; }); } } }, text: { element : function(settings, original) { var input = $('<input />'); if (settings.width != 'none') { input.width(settings.width); } if (settings.height != 'none') { input.height(settings.height); } /* https://bugzilla.mozilla.org/show_bug.cgi?id=236791 */ //input[0].setAttribute('autocomplete','off'); input.attr('autocomplete','off'); $(this).append(input); return(input); } }, textarea: { element : function(settings, original) { var textarea = $('<textarea />'); if (settings.rows) { textarea.attr('rows', settings.rows); } else if (settings.height != "none") { textarea.height(settings.height); } if (settings.cols) { textarea.attr('cols', settings.cols); } else if (settings.width != "none") { textarea.width(settings.width); } $(this).append(textarea); return(textarea); } }, select: { element : function(settings, original) { var select = $('<select />'); $(this).append(select); return(select); }, content : function(data, settings, original) { /* If it is string assume it is json. */ if (String == data.constructor) { eval ('var json = ' + data); } else { /* Otherwise assume it is a hash already. */ var json = data; } for (var key in json) { if (!json.hasOwnProperty(key)) { continue; } if ('selected' == key) { continue; } var option = $('<option />').val(key).append(json[key]); $('select', this).append(option); } /* Loop option again to set selected. IE needed this... */ $('select', this).children().each(function() { if ($(this).val() == json['selected'] || $(this).text() == $.trim(original.revert)) { $(this).attr('selected', 'selected'); } }); } } }, /* Add new input type */ addInputType: function(name, input) { $.editable.types[name] = input; } }; // publicly accessible defaults $.fn.editable.defaults = { name : 'value', id : 'id', type : 'text', width : 'auto', height : 'auto', event : 'click.editable', onblur : 'cancel', loadtype : 'GET', loadtext : 'Loading...', placeholder: 'Click to edit', loaddata : {}, submitdata : {}, ajaxoptions: {} }; })(jQuery);
JavaScript
/* * File: unit_test.js * Version: 0.0.1 * CVS: $Id$ * Description: Unit test framework * Author: Allan Jardine (www.sprymedia.co.uk) * Created: Sun Mar 8 22:02:49 GMT 2009 * Modified: $Date$ by $Author$ * Language: Javascript * License: GPL v2 or BSD 3 point style * Project: DataTables * Contact: allan.jardine@sprymedia.co.uk * * Copyright 2009 Allan Jardine, all rights reserved. * * Description: * This is a javascript library suitable for use as a unit testing framework. Employing a queuing * mechanisim to take account of async events in javascript, this library will communicates with * a controller frame (to report individual test status). * */ var oTest = { /* Block further tests from occuring - might be end of tests or due to async wait */ bBlock: false, /* Number of times to try retesting for a blocking test */ iReTestLimit: 20, /* Amount of time to wait between trying for an async test */ iReTestDelay: 150, /* End tests - external control */ bEnd: false, /* Internal variables */ _aoQueue: [], _iReTest: 0, _bFinished: false, /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Recommened public functions */ /* * Function: fnTest * Purpose: Add a test to the queue * Returns: - * Inputs: string:sMessage - name of the test * function:fnTest - function which will be evaludated to get the test result */ "fnTest": function ( sMessage, fnSetup, fnTest ) { this._aoQueue.push( { "sMessage": sMessage, "fnSetup": fnSetup, "fnTest": fnTest, "bPoll": false } ); this._fnNext(); }, /* * Function: fnWaitTest * Purpose: Add a test to the queue which has a re-test cycle * Returns: - * Inputs: string:sMessage - name of the test * function:fnTest - function which will be evaludated to get the test result */ "fnWaitTest": function ( sMessage, fnSetup, fnTest ) { this._aoQueue.push( { "sMessage": sMessage, "fnSetup": fnSetup, "fnTest": fnTest, "bPoll": true } ); this._fnNext(); }, /* * Function: fnStart * Purpose: Indicate that this is a new unit and what it is testing (message to end user) * Returns: - * Inputs: string:sMessage - message to give to the user about this unit */ "fnStart": function ( sMessage ) { window.parent.controller.fnStartMessage( sMessage ); }, /* * Function: fnComplete * Purpose: Tell the controller that we are all done here * Returns: - * Inputs: - */ "fnComplete": function () { this._bFinished = true; this._fnNext(); }, /* * Function: fnCookieDestroy * Purpose: Destroy a cookie of a given name * Returns: - * Inputs: - */ "fnCookieDestroy": function ( oTable ) { var sName = oTable.fnSettings().sCookiePrefix+oTable.fnSettings().sInstance; var aParts = window.location.pathname.split('/'); var sNameFile = sName + '_' + aParts.pop().replace(/[\/:]/g,"").toLowerCase(); document.cookie = sNameFile+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+ aParts.join('/') + "/"; }, /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Internal functions */ "_fnReTest": function ( oTestInfo ) { var bResult = oTestInfo.fnTest( ); if ( bResult ) { /* Test passed on retry */ this._fnResult( true ); this._fnNext(); } else { if ( this._iReTest < this.iReTestLimit ) { this._iReTest++; setTimeout( function() { oTest._fnReTest( oTestInfo ); }, this.iReTestDelay ); } else { this._fnResult( false ); } } }, "_fnNext": function () { if ( this.bEnd ) { return; } if ( !this.bBlock && this._aoQueue.length > 0 ) { var oNextTest = this._aoQueue.shift(); window.parent.controller.fnTestStart( oNextTest.sMessage ); this.bBlock = true; if ( typeof oNextTest.fnSetup == 'function' ) { oNextTest.fnSetup( ); } var bResult = oNextTest.fnTest( ); //bResult = false; if ( oNextTest.bPoll ) { if ( bResult ) { this._fnResult( true ); this._fnNext(); } else { _iReTest = 0; setTimeout( function() { oTest._fnReTest( oNextTest ); }, this.iReTestDelay ); } } else { this._fnResult( bResult ); this._fnNext(); } } else if ( !this.bBlock && this._aoQueue.length == 0 && this._bFinished ) { window.parent.controller.fnUnitComplete( ); } }, "_fnResult": function ( b ) { window.parent.controller.fnTestResult( b ); this.bBlock = false; if ( !b ) { this.bEnd = true; } } }; var oDispacher = { "click": function ( nNode, oSpecial ) { var evt = this.fnCreateEvent( 'click', nNode, oSpecial ); if ( nNode.dispatchEvent ) nNode.dispatchEvent(evt); else nNode.fireEvent('onclick', evt); }, "change": function ( nNode ) { var evt = this.fnCreateEvent( 'change', nNode ); if ( nNode.dispatchEvent ) nNode.dispatchEvent(evt); else nNode.fireEvent('onchange', evt); }, /* * Function: fnCreateEvent * Purpose: Create an event oject based on the type to trigger an event - x-platform * Returns: event:evt * Inputs: string:sType - type of event * node:nTarget - target node of the event */ fnCreateEvent: function( sType, nTarget, oSpecial ) { var evt = null; var oTargetPos = this._fnGetPos( nTarget ); var sTypeGroup = this._fnEventTypeGroup( sType ); if ( typeof oSpecial == 'undefined' ) { oSpecial = {}; } var ctrlKey = false; var altKey = false; var shiftKey = (typeof oSpecial.shift != 'undefined') ? oSpecial.shift : false; var metaKey = false; var button = false; if ( document.createEvent ) { switch ( sTypeGroup ) { case 'mouse': evt = document.createEvent( "MouseEvents" ); evt.initMouseEvent( sType, true, true, window, 0, oTargetPos[0], oTargetPos[1], oTargetPos[0], oTargetPos[1], ctrlKey, altKey, shiftKey, metaKey, button, null ); break; case 'html': evt = document.createEvent( "HTMLEvents" ); evt.initEvent( sType, true, true ); break; case 'ui': evt = document.createEvent( "UIEvents" ); evt.initUIEvent( sType, true, true, window, 0 ); break; default: break; } } else if ( document.createEventObject ) { switch ( sTypeGroup ) { case 'mouse': evt = document.createEventObject(); evt.screenX = oTargetPos[0]; evt.screenX = oTargetPos[1]; evt.clientX = oTargetPos[0]; evt.clientY = oTargetPos[1]; evt.ctrlKey = ctrlKey; evt.altKey = altKey; evt.shiftKey = shiftKey; evt.metaKey = metaKey; evt.button = button; evt.relatedTarget = null; break; case 'html': /* fall through to basic event object */ case 'ui': evt = document.createEventObject(); break; default: break; } } return evt; }, /* * Function: DesignCore.fnGetPos * Purpose: Get the position of an element on the page * Returns: array[ 0-int:left, 1-int:top ] * Inputs: node:obj - node to analyse */ _fnGetPos: function ( obj ) { var curleft = 0; var curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft; curtop = obj.offsetTop; while (obj = obj.offsetParent ) { curleft += obj.offsetLeft; curtop += obj.offsetTop; } } return [curleft,curtop]; }, /* * Function: _fnEventTypeGroup * Purpose: Group the event types as per w3c groupings * Returns: - * Inputs: string:sType */ _fnEventTypeGroup: function ( sType ) { switch ( sType ) { case 'click': case 'dblclick': case 'mousedown': case 'mousemove': case 'mouseout': case 'mouseover': case 'mouseup': return 'mouse'; case 'change': case 'focus': case 'blur': case 'select': case 'submit': return 'html'; case 'keydown': case 'keypress': case 'keyup': case 'load': case 'unload': return 'ui'; default: return 'custom'; } } } var oSession = { nTable: null, fnCache: function () { this.nTable = document.getElementById('demo').cloneNode(true); }, fnRestore: function () { while( $.fn.dataTableSettings.length > 0 ) { try { $.fn.dataTableSettings[0].oInstance.fnDestroy(); } catch (e) { $.fn.dataTableSettings.splice( 0, 1 ); } } //$.fn.dataTableSettings.splice( 0, $.fn.dataTableSettings.length ); var nDemo = document.getElementById('demo'); nDemo.innerHTML = ""; for ( var i=0, iLen=this.nTable.childNodes.length ; i<iLen ; i++ ) { nDemo.appendChild( this.nTable.childNodes[0] ); } this.fnCache(); } } $(document).ready( function () { oSession.fnCache(); } );
JavaScript
var giTotalTestCount = 0; var giActiveModule = 0; var giModuleTests; var giStartTime; var giTest; var gbStop = false; var gtoTest; function fnTestStart ( sTestInfo ) { gaoTest[ giActiveModule ].iTests++; document.getElementById('test_info').innerHTML += (giActiveModule+1)+'.'+(giModuleTests+1)+'. '+sTestInfo+'... '; document.getElementById('test_number').innerHTML = giTotalTestCount+1; giModuleTests++; giTotalTestCount++; /* Set a timer to catch stalled script */ gtoTest = setTimeout( function () { fnMessage( '<span class="error">WARNING - test script stalled. Likely a JS error</span>' ); gbStop = true; }, 3000 ); } function fnTestResult ( bResult ) { clearTimeout( gtoTest ); if ( bResult ) { fnMessage( 'Passed' ); } else { fnMessage( '<span class="error">FAILED</span>' ); gbStop = true; fnEnd( false ); } } function fnUnitStart( iTest ) { if ( !gbStop ) { giModuleTests = 0; window.parent.test_arena.location.href = (iTest==0?"":"../")+'templates/'+gaoTest[iTest].sTemplate+'.php?scripts='+gaoTest[iTest].sTest; giTest = iTest; } } function fnStartMessage( sMessage ) { fnMessage( '<br><b>'+gaoTest[giTest].sGroup+' - '+sMessage+'</b>' ); } function fnMessage( sMessage ) { var nInfo = document.getElementById('test_info'); nInfo.innerHTML += sMessage+'<br>'; nInfo.scrollTop = nInfo.scrollHeight; } function fnUnitComplete() { if ( giActiveModule < gaoTest.length - 1 ) { fnUnitStart( ++giActiveModule ); } else { fnEnd( true ); } } function fnEnd( bSuccess ) { var iEndTime = new Date().getTime(); var sTime = '<br>This test run took '+parseInt((iEndTime-giStartTime)/1000, 10)+ ' second(s) to complete.'; if ( bSuccess ) { $('#test_running').html( 'Tests complete. '+giTotalTestCount+' tests were run.'+sTime ); } else { $('#test_running').html( 'Unit tests failed at test '+giTotalTestCount+'.'+sTime ); } } $(document).ready( function () { giStartTime = new Date().getTime(); fnUnitStart( giActiveModule ); } );
JavaScript
// DATA_TEMPLATE: dom_data oTest.fnStart( "Sanity checks for DataTables with DOM data" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { $('#example').dataTable(); /* Basic checks */ oTest.fnTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable(); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sClass" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "By default the test class hasn't been applied to the column (sanity!)", null, function () { return $('#example tbody tr:eq(0) td:eq(2)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - first row", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, null, { "sClass": 'unittest' }, null, null ] } ); }, function () { return $('#example tbody tr:eq(1) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - third row", null, function () { return $('#example tbody tr:eq(3) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - last row", null, function () { return $('#example tbody tr:eq(9) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to other columns - 1st", null, function () { return $('#example tbody tr:eq(3) td:eq(0)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to other columns - 5th", null, function () { return $('#example tbody tr:eq(3) td:eq(4)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - seventh row - second page", function () { $('#example_next').click(); }, function () { return $('#example tbody tr:eq(6) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to header", null, function () { return $('#example thead tr:eq(3) th:eq(4)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to footer", null, function () { return $('#example thead tr:eq(3) th:eq(4)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Class defined for multiple columns - first row", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ { "sClass": 'unittest2' }, null, null, { "sClass": 'unittest1' }, null ] } ); }, function () { var bReturn = $('#example tbody tr:eq(3) td:eq(0)').hasClass('unittest2') && $('#example tbody tr:eq(8) td:eq(3)').hasClass('unittest1'); return bReturn; } ); oTest.fnWaitTest( "Class defined for multiple columns - has not applied to other columns - 5th 1", null, function () { return $('#example tbody tr:eq(0) td:eq(4)').hasClass('unittest1') == false; } ); oTest.fnWaitTest( "Class defined for multiple columns - has not applied to other columns - 5th 2", null, function () { return $('#example tbody tr:eq(6) td:eq(4)').hasClass('unittest2') == false; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aaSorting" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default sorting is single column", null, function () { return oSettings.aaSorting.length == 1 && typeof oSettings.aaSorting[0] == 'object'; } ); oTest.fnWaitTest( "Default sorting is first column asc", null, function () { return oSettings.aaSorting[0].length == 3 && oSettings.aaSorting[0][0] == 0 && oSettings.aaSorting[0][1] == 'asc'; } ); oTest.fnWaitTest( "Sorting is applied", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnWaitTest( "Custom sorting on single string column asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Custom sorting on single string column desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Custom sorting on single int column asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['1','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnWaitTest( "Custom sorting on single int column desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','asc'], ['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Camino 1.0"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / string desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','asc'], ['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','desc'], ['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "iPod Touch / iPhone"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / string desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','desc'], ['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Safari 3.0"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / int asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','asc'], ['3','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "1"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / int desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','asc'], ['3','desc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "1.9"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / int asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','desc'], ['3','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "125.5"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / int desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','desc'], ['3','desc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnWaitTest( "Multi-column sorting (3 column) - string asc / int asc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSorting": [['0','asc'], ['3','asc'], ['1','asc']] } ); }, function () { return $('#example tbody tr:eq(7) td:eq(1)').html() == "Firefox 1.0"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoSearchCols" ); /* We could be here forever testing this one, so we test a limited subset on a couple of colums */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default should be to have a empty colums array", null, function () { var bReturn = oSettings.aoPreSearchCols[0].sSearch == 0 && !oSettings.aoPreSearchCols[0].bRegex && oSettings.aoPreSearchCols[1].sSearch == 0 && !oSettings.aoPreSearchCols[1].bRegex && oSettings.aoPreSearchCols[2].sSearch == 0 && !oSettings.aoPreSearchCols[2].bRegex && oSettings.aoPreSearchCols[3].sSearch == 0 && !oSettings.aoPreSearchCols[3].bRegex && oSettings.aoPreSearchCols[4].sSearch == 0 && !oSettings.aoPreSearchCols[4].bRegex; return bReturn; } ); oTest.fnWaitTest( "Search on a single column - no regex statement given", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoSearchCols": [ null, { "sSearch": "Mozilla" }, null, { "sSearch": "1" }, null ] } ); }, function () { return $('#example_info').html() == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnWaitTest( "Search on two columns - no regex statement given", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoSearchCols": [ null, { "sSearch": "Mozilla" }, null, { "sSearch": "1.5" }, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "1.5"; } ); oTest.fnWaitTest( "Search on single column - escape regex false", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoSearchCols": [ { "sSearch": ".*ML", "bEscapeRegex": false }, null, null, null, null ] } ); }, function () { return $('#example_info').html() == "Showing 1 to 3 of 3 entries (filtered from 57 total entries)"; } ); oTest.fnWaitTest( "Search on two columns - escape regex false on first, true on second", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoSearchCols": [ { "sSearch": ".*ML", "bEscapeRegex": false }, { "sSearch": "3.3", "bEscapeRegex": true }, null, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Konqureror 3.3"; } ); oTest.fnWaitTest( "Search on two columns (no records) - escape regex false on first, true on second", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoSearchCols": [ { "sSearch": ".*ML", "bEscapeRegex": false }, { "sSearch": "Allan", "bEscapeRegex": true }, null, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aaSortingFixed" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "No fixed sorting by default", null, function () { return oSettings.aaSortingFixed == null; } ); oTest.fnWaitTest( "Fixed sorting on first column (string/asc) with user sorting on second column (string/asc)", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSortingFixed": [['0','asc']], "fnInitComplete": function () { $('#example thead th:eq(1)').click(); } } ); // }, function () { return $('#example tbody td:eq(1)').html() == "Camino 1.0"; } ); oTest.fnWaitTest( "Fixed sorting on first column (string/asc) with user sorting on second column (string/desc)", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Fixed sorting on fourth column (int/asc) with user sorting on second column (string/asc)", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aaSortingFixed": [['3','asc']] } ); $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Fixed sorting on fourth column (int/asc) with user sorting on second column (string/desc)", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "PSP browser"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnInitComplete" ); /* Fairly boring function compared to the others! */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); var mPass; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnInitComplete == null; } ); oTest.fnWaitTest( "Two arguments passed (for Ajax!)", function () { oSession.fnRestore(); mPass = -1; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnInitComplete": function ( ) { mPass = arguments.length; } } ); }, function () { return mPass == 2; } ); oTest.fnWaitTest( "That one argument is the settings object", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnInitComplete": function ( oSettings ) { mPass = oSettings; } } ); }, function () { return oTable.fnSettings() == mPass; } ); oTest.fnWaitTest( "fnInitComplete called once on first draw", function () { oSession.fnRestore(); mPass = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnInitComplete": function ( ) { mPass++; } } ); }, function () { return mPass == 1; } ); oTest.fnWaitTest( "fnInitComplete never called there after", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return mPass == 1; } ); oTest.fnWaitTest( "10 rows in the table on complete", function () { oSession.fnRestore(); mPass = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnInitComplete": function ( ) { mPass = $('#example tbody tr').length; } } ); }, function () { return mPass == 10; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.fnRender" ); $(document).ready( function () { /* Check the default */ var mTmp = 0; var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "fnRender": function (a) { mTmp++; return a.aData[a.iDataColumn]; } }, null, null, null ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Single column - fnRender is called twice for each row", null, function () { return mTmp == 57; } ); oTest.fnWaitTest( "Confirm that fnRender passes two arguments with four parameters", function () { mTmp = true; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "fnRender": function (a) { if ( arguments.length != 2 || typeof a.iDataRow=='undefined' || typeof a.iDataColumn=='undefined' || typeof a.aData=='undefined' || typeof a.mDataProp=='undefined' ) { mTmp = false; } return a.aData[a.iDataColumn]; } }, null, null, null ] } ); }, function () { return mTmp; } ); oTest.fnWaitTest( "fnRender iDataColumn is the column", function () { mTmp = true; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "fnRender": function (a) { if ( a.iDataColumn != 1 ) { mTmp = false; } return a.aData[a.iDataColumn]; } }, null, null, null ] } ); }, function () { return mTmp; } ); oTest.fnWaitTest( "fnRender aData is data array of correct size", function () { mTmp = true; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "fnRender": function (a) { if ( a.aData.length != 5 ) { mTmp = false; } return a.aData[a.iDataColumn]; } }, null, null, null ] } ); }, function () { return mTmp; } ); oTest.fnWaitTest( "Passed back data is put into the DOM", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "fnRender": function (a) { return 'unittest'; } }, null, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'unittest'; } ); oTest.fnWaitTest( "Passed back data is put into the DOM", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, null, { "fnRender": function (a) { return 'unittest1'; } }, { "fnRender": function (a) { return 'unittest2'; } }, null ] } ); }, function () { var bReturn = $('#example tbody tr:eq(0) td:eq(2)').html() == 'unittest1' && $('#example tbody tr:eq(0) td:eq(3)').html() == 'unittest2'; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sWidth" ); /* NOTE - we need to disable the auto width for the majority of these test in order to preform * these tests as the auto width will convert the width to a px value. We can do 'non-exact' tests * with auto width enabled however to ensure it scales columns as required */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bAutoWidth": false, "aoColumns": [ null, { "sWidth": '40%' }, null, null, null ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "With auto width disabled the width for one column is appled", null, function () { return $('#example thead th:eq(1)')[0].style.width == "40%"; } ); oTest.fnWaitTest( "With auto width disabled the width for one column is appled", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bAutoWidth": false, "aoColumns": [ null, null, { "sWidth": '20%' }, { "sWidth": '30%' }, null ] } ); }, function () { var bReturn = $('#example thead th:eq(2)')[0].style.width == "20%" && $('#example thead th:eq(3)')[0].style.width == "30%"; return bReturn; } ); oTest.fnWaitTest( "With auto width, it will make the smallest column the largest with percentage width given", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, null, null, { "sWidth": '40%' }, null ] } ); }, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; if ( a3>a0 && a3>a1 && a3>a2 && a3>a4 ) return true; else return false; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sName" ); /* This has no effect at all in DOM methods - so we just check that it has applied the name */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, null, null, { "sName": 'unit test' }, null ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Names are stored in the columns object", null, function () { return oSettings.aoColumns[3].sName =="unit test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnRowCallback" ); /* Note - fnRowCallback MUST return the first arguments (modified or not) */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); var mPass; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnRowCallback == null; } ); oTest.fnWaitTest( "Four arguments passed", function () { oSession.fnRestore(); mPass = -1; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnRowCallback": function ( nTr ) { mPass = arguments.length; return nTr; } } ); }, function () { return mPass == 4; } ); oTest.fnWaitTest( "fnRowCallback called once for each drawn row", function () { oSession.fnRestore(); mPass = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { mPass++; return nTr; } } ); }, function () { return mPass == 10; } ); oTest.fnWaitTest( "fnRowCallback allows us to alter row information", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { $(nTr).addClass('unit_test'); return nTr; } } ); }, function () { return $('#example tbody tr:eq(1)').hasClass('unit_test'); } ); oTest.fnWaitTest( "Data array has length matching columns", function () { oSession.fnRestore(); mPass = true; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { if ( asData.length != 5 ) mPass = false; return nTr; } } ); }, function () { return mPass; } ); oTest.fnWaitTest( "Data array has length matching columns", function () { oSession.fnRestore(); mPass = true; var iCount = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { if ( iCount != iDrawIndex ) mPass = false; iCount++; return nTr; } } ); }, function () { return mPass; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sTitle" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "If not given, then the columns titles are empty", null, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "Browser" && jqNodes[2].innerHTML == "Platform(s)" && jqNodes[3].innerHTML == "Engine version" && jqNodes[4].innerHTML == "CSS grade"; return bReturn; } ); oTest.fnWaitTest( "Can set a single column title - and others are read from DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "sTitle": 'unit test' }, null, null, null ] } ); }, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "unit test" && jqNodes[2].innerHTML == "Platform(s)" && jqNodes[3].innerHTML == "Engine version" && jqNodes[4].innerHTML == "CSS grade"; return bReturn; } ); oTest.fnWaitTest( "Can set multiple column titles", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "sTitle": 'unit test 1' }, null, null, { "sTitle": 'unit test 2' } ] } ); }, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "unit test 1" && jqNodes[2].innerHTML == "Platform(s)" && jqNodes[3].innerHTML == "Engine version" && jqNodes[4].innerHTML == "unit test 2"; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "iDisplayLength" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Default length is ten", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnWaitTest( "Select menu shows 10", null, function () { return $('#example_length select').val() == 10; } ); oTest.fnWaitTest( "Set initial length to 25", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "iDisplayLength": 25 } ); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnWaitTest( "Select menu shows 25", null, function () { return $('#example_length select').val() == 25; } ); oTest.fnWaitTest( "Set initial length to 100", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "iDisplayLength": 100 } ); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnWaitTest( "Select menu shows 25", null, function () { return $('#example_length select').val() == 100; } ); oTest.fnWaitTest( "Set initial length to 23 (unknown select menu length)", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "iDisplayLength": 23 } ); }, function () { return $('#example tbody tr').length == 23; } ); oTest.fnWaitTest( "Select menu shows 10 (since 23 is unknow)", null, function () { return $('#example_length select').val() == 10; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bFilter" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Filtering div exists by default", null, function () { return document.getElementById('example_filter') != null; } ); /* Check can disable */ oTest.fnWaitTest( "Fltering can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bFilter": false } ); }, function () { return document.getElementById('example_filter') == null; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Filtering enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bFilter": true } ); }, function () { return document.getElementById('example_filter') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sSearch" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Search language is 'Search:' by default", null, function () { return oSettings.oLanguage.sSearch == "Search:"; } ); oTest.fnTest( "A label input is used", null, function () { return $('label', oSettings.aanFeatures.f[0]).length == 1 } ); oTest.fnTest( "Search language default is in the DOM", null, function () { return $('label', oSettings.aanFeatures.f[0]).text() == "Search: "; } ); oTest.fnWaitTest( "Search language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sSearch": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sSearch == "unit test"; } ); oTest.fnTest( "Info language definition is in the DOM", null, function () { return $('label', oSettings.aanFeatures.f[0]).text().indexOf('unit test') !== -1; } ); oTest.fnWaitTest( "Blank search has a no space (separator) inserted", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sSearch": "" } } ); oSettings = oTable.fnSettings(); }, function () { return document.getElementById('example_filter').childNodes.length == 1; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bPaginate" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Pagiantion div exists by default", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnWaitTest( "Information div takes paging into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* Check can disable */ oTest.fnWaitTest( "Pagiantion can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bPaginate": false } ); }, function () { return document.getElementById('example_paginate') == null; } ); oTest.fnWaitTest( "Information div takes paging disabled into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Pagiantion enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bPaginate": true } ); }, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sUrl" ); /* Note that we only test the internal storage of language information pulled form a file here * as the other language tests will check it goes into the DOM correctly */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnTest( "sUrl is blank by default", null, function () { return oSettings.oLanguage.sUrl == ""; } ); oTest.fnWaitTest( "Loading of German file loads language information", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sUrl": "../../../examples/examples_support/de_DE.txt" } } ); oSettings = oTable.fnSettings(); }, function () { var bReturn = oSettings.oLanguage.sProcessing == "Bitte warten..." && oSettings.oLanguage.sLengthMenu == "_MENU_ Einträge anzeigen" && oSettings.oLanguage.sZeroRecords == "Keine Einträge vorhanden." && oSettings.oLanguage.sInfo == "_START_ bis _END_ von _TOTAL_ Einträgen" && oSettings.oLanguage.sInfoEmpty == "0 bis 0 von 0 Einträgen" && oSettings.oLanguage.sInfoFiltered == "(gefiltert von _MAX_ Einträgen)" && oSettings.oLanguage.sInfoPostFix == "" && oSettings.oLanguage.sSearch == "Suchen" && oSettings.oLanguage.oPaginate.sFirst == "Erster" && oSettings.oLanguage.oPaginate.sPrevious == "Zurück" && oSettings.oLanguage.oPaginate.sNext == "Nächster" && oSettings.oLanguage.oPaginate.sLast == "Letzter"; return bReturn; } ); /* One DOM check just to ensure that they go into the DOM */ oTest.fnTest( "Loaded language goes into the DOM", null, function () { return document.getElementById('example_info').innerHTML = "1 bis 10 von 57 Einträgen"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bSort" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Sorting is on by default", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnWaitTest( "Sorting Asc by default class applied", null, function () { return $('#example thead th:eq(0)').hasClass("sorting_asc"); } ); oTest.fnWaitTest( "Click on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Sorting class removed from first column", null, function () { return $('#example thead th:eq(0)').hasClass("sorting_asc") != true; } ); oTest.fnWaitTest( "Sorting asc class applied to second column", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_asc"); } ); oTest.fnWaitTest( "Reverse on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Sorting acs class removed from second column", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_asc") != true; } ); oTest.fnWaitTest( "Sorting desc class applied to second column", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_desc"); } ); /* Check can disable */ oTest.fnWaitTest( "Pagiantion can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bSort": false } ); }, function () { return $('#example tbody td:eq(3)').html() == "4"; } ); oTest.fnWaitTest( "Click on second column has no effect", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "4"; } ); oTest.fnWaitTest( "Reverse on second column has no effect", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "4"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Sorting enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bSort": true } ); }, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "sAjaxSource" ); /* Sanitfy check really - all the other tests blast this */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Server side is off by default", null, function () { return oSettings.sAjaxSource == "../../../examples/ajax/sources/arrays.txt"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sProcessing" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bProcessing": true } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Processing language is 'Processing...' by default", null, function () { return oSettings.oLanguage.sProcessing == "Processing..."; } ); oTest.fnTest( "Processing language default is in the DOM", null, function () { return document.getElementById('example_processing').innerHTML = "Processing..."; } ); oTest.fnWaitTest( "Processing language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bProcessing": true, "oLanguage": { "sProcessing": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sProcessing == "unit test"; } ); oTest.fnTest( "Processing language definition is in the DOM", null, function () { return document.getElementById('example_processing').innerHTML = "unit test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oSearch" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default values should be blank", null, function () { var bReturn = oSettings.oPreviousSearch.sSearch == "" && !oSettings.oPreviousSearch.bRegex; return bReturn; } ); /* This test might be considered iffy since the full object isn't given, but it's reasonable to * expect DataTables to cope with this. It should just assumine regex false */ oTest.fnWaitTest( "Search term only in object", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oSearch": { "sSearch": "Mozilla" } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnWaitTest( "New search will kill old one", function () { oTable.fnFilter("Opera"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Presto"; } ); oTest.fnWaitTest( "Search plain text term and escape regex true", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oSearch": { "sSearch": "DS", "bRegex": false } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Nintendo DS browser"; } ); oTest.fnWaitTest( "Search plain text term and escape regex false", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oSearch": { "sSearch": "Opera", "bRegex": true } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Presto"; } ); oTest.fnWaitTest( "Search regex text term and escape regex true", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oSearch": { "sSearch": "1.*", "bRegex": false } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnWaitTest( "Search regex text term and escape regex false", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oSearch": { "sSearch": "1.*", "bRegex": true } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sLoadingRecords" ); $(document).ready( function () { var tmp = false; oTest.fnTest( "Default loading text is 'Loading...'", function () { $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); tmp = $('#example tbody tr td')[0].innerHTML == "Loading..."; }, function () { return tmp; } ); oTest.fnTest( "Text can be overriden", function () { oSession.fnRestore(); $('#example').dataTable( { "oLanguage": { "sLoadingRecords": "unitest" }, "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); tmp = $('#example tbody tr td')[0].innerHTML == "unitest"; }, function () { return tmp; } ); oTest.fnTest( "When sZeroRecords is given but sLoadingRecords is not, sZeroRecords is used", function () { oSession.fnRestore(); $('#example').dataTable( { "oLanguage": { "sZeroRecords": "unitest_sZeroRecords" }, "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); tmp = $('#example tbody tr td')[0].innerHTML == "unitest_sZeroRecords"; }, function () { return tmp; } ); oTest.fnTest( "sLoadingRecords and sZeroRecords both given", function () { oSession.fnRestore(); $('#example').dataTable( { "oLanguage": { "sZeroRecords": "unitest_sZeroRecords2", "sLoadingRecords": "unitest2" }, "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); tmp = $('#example tbody tr td')[0].innerHTML == "unitest2"; }, function () { return tmp; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnCreatedRow tests" ); $(document).ready( function () { var tmp = 0; var complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", fnCreatedRow: function () { tmp++; } } ); oTest.fnWaitTest( "Row created is called once for each row on init", null, function () { return tmp===57; } ); oTest.fnTest( "Created isn't called back on other draws", function () { $('#example th:eq(1)').click(); }, function () { return tmp===57; } ); oTest.fnWaitTest( "Three arguments for the function", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", fnCreatedRow: function () { if ( arguments.length !== 3 ) { tmp = false; } }, fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "First argument is a TR element", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", fnCreatedRow: function () { if ( arguments[0].nodeName !== "TR" ) { tmp = false; } }, fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "Second argument is an array with 5 elements", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", fnCreatedRow: function () { if ( arguments[1].length !== 5 ) { tmp = false; } }, fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "Third argument is the data source for the row", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", fnCreatedRow: function () { if ( arguments[1] !== this.fnSettings().aoData[ arguments[2] ]._aData ) { tmp = false; } }, fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "TR element is tied to the correct data", function () { oSession.fnRestore(); tmp = false; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", fnCreatedRow: function (tr, data, index) { if ( data[1] === "Firefox 1.0" ) { if ( $('td:eq(3)', tr).html() == "1.7" ) { tmp = true; } } }, fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sZeroRecords" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Zero records language is 'No matching records found' by default", null, function () { return oSettings.oLanguage.sZeroRecords == "No matching records found"; } ); oTest.fnWaitTest( "Text is shown when empty table (after filtering)", function () { oTable.fnFilter('nothinghere'); }, function () { return $('#example tbody tr td')[0].innerHTML == "No matching records found" } ); oTest.fnWaitTest( "Zero records language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sZeroRecords": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sZeroRecords == "unit test"; } ); oTest.fnWaitTest( "Text is shown when empty table (after filtering)", function () { oTable.fnFilter('nothinghere2'); }, function () { return $('#example tbody tr td')[0].innerHTML == "unit test" } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.oPaginate" ); /* Note that the paging language information only has relevence in full numbers */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sPaginationType": "full_numbers" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "oLanguage.oPaginate defaults", null, function () { var bReturn = oSettings.oLanguage.oPaginate.sFirst == "First" && oSettings.oLanguage.oPaginate.sPrevious == "Previous" && oSettings.oLanguage.oPaginate.sNext == "Next" && oSettings.oLanguage.oPaginate.sLast == "Last"; return bReturn; } ); oTest.fnTest( "oLanguage.oPaginate defaults are in the DOM", null, function () { var bReturn = $('#example_paginate .first').html() == "First" && $('#example_paginate .previous').html() == "Previous" && $('#example_paginate .next').html() == "Next" && $('#example_paginate .last').html() == "Last"; return bReturn; } ); oTest.fnWaitTest( "oLanguage.oPaginate can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sPaginationType": "full_numbers", "oLanguage": { "oPaginate": { "sFirst": "unit1", "sPrevious": "test2", "sNext": "unit3", "sLast": "test4" } } } ); oSettings = oTable.fnSettings(); }, function () { var bReturn = oSettings.oLanguage.oPaginate.sFirst == "unit1" && oSettings.oLanguage.oPaginate.sPrevious == "test2" && oSettings.oLanguage.oPaginate.sNext == "unit3" && oSettings.oLanguage.oPaginate.sLast == "test4"; return bReturn; } ); oTest.fnTest( "oLanguage.oPaginate definitions are in the DOM", null, function () { var bReturn = $('#example_paginate .first').html() == "unit1" && $('#example_paginate .previous').html() == "test2" && $('#example_paginate .next').html() == "unit3" && $('#example_paginate .last').html() == "test4"; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnDrawCallback" ); /* Fairly boring function compared to the others! */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); var mPass, bInit; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnDrawCallback == null; } ); oTest.fnWaitTest( "One argument passed", function () { oSession.fnRestore(); mPass = -1; bInit = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnDrawCallback": function ( ) { mPass = arguments.length; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return mPass == 1 && bInit; } ); oTest.fnWaitTest( "That one argument is the settings object", function () { oSession.fnRestore(); bInit = false; oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnDrawCallback": function ( oSettings ) { mPass = oSettings; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return oTable.fnSettings() == mPass && bInit; } ); /* The draw callback is called once for the init and then when the data is added */ oTest.fnWaitTest( "fnRowCallback called once on first draw", function () { oSession.fnRestore(); mPass = 0; bInit = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnDrawCallback": function ( ) { mPass++; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return mPass == 2 && bInit; } ); oTest.fnWaitTest( "fnRowCallback called once on each draw there after as well", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return mPass == 5; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bAutoWidth" ); /* It's actually a little tricky to test this. We can't test absolute numbers because * different browsers and different platforms will render the width of the columns slightly * differently. However, we certainly can test the principle of what should happen (column * width doesn't change over pages) */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Auto width is enabled by default", null, function () { return oSettings.oFeatures.bAutoWidth; } ); oTest.fnWaitTest( "First column has a width assigned to it", null, function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); } ); /* This would seem like a better test - but there appear to be difficulties with tables which are bigger (calculated) than there is actually room for. I suspect this is actually a bug in datatables oTest.fnWaitTest( "Check column widths on first page match second page", null, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; $('#example_next').click(); var b0 = anThs[0].offsetWidth; var b1 = anThs[1].offsetWidth; var b2 = anThs[2].offsetWidth; var b3 = anThs[3].offsetWidth; var b4 = anThs[4].offsetWidth; console.log( a0, b0, a1, b1, a2, b2, a3, b3 ); if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) return true; else return false; } ); oTest.fnWaitTest( "Check column widths on second page match thid page", null, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; $('#example_next').click(); var b0 = anThs[0].offsetWidth; var b1 = anThs[1].offsetWidth; var b2 = anThs[2].offsetWidth; var b3 = anThs[3].offsetWidth; var b4 = anThs[4].offsetWidth; if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) return true; else return false; } ); */ /* Check can disable */ oTest.fnWaitTest( "Auto width can be disabled", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bAutoWidth": false } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bAutoWidth == false; } ); oTest.fnWaitTest( "First column does not have a width assigned to it", null, function () { return $('#example thead th:eq(0)').attr('style') == null; } ); /* oTest.fnWaitTest( "Check column widths on first page do not match second page", null, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; $('#example_next').click(); var b0 = anThs[0].offsetWidth; var b1 = anThs[1].offsetWidth; var b2 = anThs[2].offsetWidth; var b3 = anThs[3].offsetWidth; var b4 = anThs[4].offsetWidth; if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) return false; else return true; } ); */ /* Enable makes no difference */ oTest.fnWaitTest( "Auto width enabled override", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bAutoWidth": true } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bAutoWidth; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bUseRendered" ); /* bUseRendered is used to alter sorting data, if false then the original data is used for * sorting rather than the rendered data */ $(document).ready( function () { /* Check the default */ var mTmp = 0; var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "fnRender": function (a) { if ( mTmp == 0 ) { mTmp++; return "aaa"; } else return a.aData[a.iDataColumn]; } }, null, null, null ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default for bUseRendered is true - rendered data is used for sorting", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'aaa'; } ); oTest.fnWaitTest( "When bUseRendered is false, original data is used for sorting", function () { mTmp = 0; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "bUseRendered": false, "fnRender": function (a) { if ( mTmp == 0 ) { mTmp++; return "aaa"; } else { return a.aData[a.iDataColumn]; } } }, null, null, null ] } ); $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; } ); oTest.fnWaitTest( "bUseRendered set to false on one columns and true (default) on two others", function () { mTmp = 0; var mTmp2 = 0; var mTmp3 = 0; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ { "fnRender": function (a) { if ( mTmp == 0 ) { mTmp++; return "aaa1"; } else { return a.aData[a.iDataColumn]; } } }, { "bUseRendered": false, "fnRender": function (a) { if ( mTmp2 == 0 ) { mTmp2++; return "aaa2"; } else { return a.aData[a.iDataColumn]; } } }, { "fnRender": function (a) { if ( mTmp3 == 0 ) { mTmp3++; return "zzz3"; } else { return a.aData[a.iDataColumn]; } } }, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'aaa1'; } ); oTest.fnWaitTest( "Multi-column rendering - 2nd column sorting", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; } ); oTest.fnWaitTest( "Multi-column rendering - 3rd column sorting", function () { $('#example thead th:eq(2)').click(); $('#example thead th:eq(2)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(2)').html() == 'zzz3'; } ); oTest.fnWaitTest( "Multi-column rendering - 4th column sorting", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == '-'; } ); oTest.fnWaitTest( "Multi-column rendering - 5th column sorting", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnServerData for Ajax sourced data" ); $(document).ready( function () { var mPass; oTest.fnTest( "Argument length", function () { $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnServerData": function () { mPass = arguments.length; } } ); }, function () { return mPass == 4; } ); oTest.fnTest( "Url", function () { $('#example').dataTable( { "bDestroy": true, "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnServerData": function (sUrl, aoData, fnCallback, oSettings) { mPass = sUrl == "../../../examples/ajax/sources/arrays.txt"; } } ); }, function () { return mPass; } ); oTest.fnTest( "Data array", function () { $('#example').dataTable( { "bDestroy": true, "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnServerData": function (sUrl, aoData, fnCallback, oSettings) { mPass = aoData.length==0; } } ); }, function () { return mPass; } ); oTest.fnTest( "Callback function", function () { $('#example').dataTable( { "bDestroy": true, "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnServerData": function (sUrl, aoData, fnCallback, oSettings) { mPass = typeof fnCallback == 'function'; } } ); }, function () { return mPass; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bLengthChange" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Length div exists by default", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnWaitTest( "Four default options", null, function () { return $("select[name=example_length] option").length == 4; } ); oTest.fnWaitTest( "Default options", null, function () { var opts = $("select[name='example_length'] option"); return opts[0].getAttribute('value') == 10 && opts[1].getAttribute('value') == 25 && opts[2].getAttribute('value') == 50 && opts[3].getAttribute('value') == 100; } ); oTest.fnWaitTest( "Info takes length into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* Check can disable */ oTest.fnWaitTest( "Change length can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bLengthChange": false } ); }, function () { return document.getElementById('example_length') == null; } ); oTest.fnWaitTest( "Information takes length disabled into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Length change enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bLengthChange": true } ); }, function () { return document.getElementById('example_length') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnCreatedCell tests" ); $(document).ready( function () { var tmp = 0; var complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedCell: function () { tmp++; }, "aTargets": ["_all"] } ] } ); oTest.fnWaitTest( "Cell created is called once for each cell on init", null, function () { return tmp===285; } ); oTest.fnTest( "Created isn't called back on other draws", function () { $('#example th:eq(1)').click(); }, function () { return tmp===285; } ); oTest.fnWaitTest( "Four arguments for the function", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedRow: function () { if ( arguments.length !== 4 ) { tmp = false; } }, "aTargets": ["_all"] } ], fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "First argument is a TD element", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedRow: function () { if ( arguments[0].nodeName !== "TD" ) { tmp = false; } }, "aTargets": ["_all"] } ], fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "Second argument is the HTML value", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedRow: function () { if ( arguments[1] != $('td').html() ) { tmp = false; } }, "aTargets": ["_all"] } ], fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "Third argument is the data array", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedRow: function () { if ( arguments[2].length !== 5 ) { tmp = false; } }, "aTargets": ["_all"] } ], fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "Fourth argument is the data source for the row", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedRow: function () { if ( arguments[2] !== this.fnSettings().aoData[ arguments[2] ]._aData ) { tmp = false; } }, "aTargets": ["_all"] } ], fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnWaitTest( "Fifth argument is the the col index", function () { oSession.fnRestore(); tmp = true; complete = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumnDefs": [ { fnCreatedRow: function () { if ( arguments[1] != $('td:eq('+arguments[4]+')', arguments[0].parentNode).html() ) { tmp = false; } }, "aTargets": ["_all"] } ], fnInitComplete: function () { complete = true; } } ); }, function () { return (tmp && complete); } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bSortable" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "All columns are sortable by default", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Can disable sorting from one column", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "bSortable": false }, null, null, null ] } ); $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() != "All others"; } ); oTest.fnWaitTest( "Disabled column has no sorting class", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_asc") == false; } ); oTest.fnWaitTest( "Other columns can still sort", function () { $('#example thead th:eq(4)').click(); $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == "X"; } ); oTest.fnWaitTest( "Disable sorting on multiple columns - no sorting classes", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "bSortable": false }, null, { "bSortable": false }, null ] } ); }, function () { var bReturn = $('#example thead th:eq(1)').hasClass("sorting") || $('#example thead th:eq(3)').hasClass("sorting") return bReturn == false; } ); oTest.fnWaitTest( "Sorting on disabled column 1 has no effect", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() != "All others"; } ); oTest.fnWaitTest( "Sorting on disabled column 2 has no effect", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() != "-"; } ); oTest.fnWaitTest( "Second sort on disabled column 2 has no effect", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() != "-"; } ); oTest.fnWaitTest( "Even with multiple disabled sorting columns other columns can still sort", function () { $('#example thead th:eq(4)').click(); $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == "X"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bInfo" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Info div exists by default", null, function () { return document.getElementById('example_info') != null; } ); /* Check can disable */ oTest.fnWaitTest( "Info can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bInfo": false } ); }, function () { return document.getElementById('example_info') == null; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Info enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bInfo": true } ); }, function () { return document.getElementById('example_info') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bSortClasses" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Sorting classes are applied by default", null, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'); } ); oTest.fnWaitTest( "Sorting classes are applied to all required cells", null, function () { return $('#example tbody tr:eq(7) td:eq(0)').hasClass('sorting_1'); } ); oTest.fnWaitTest( "Sorting classes are not applied to non-sorting columns", null, function () { return $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_1') == false; } ); oTest.fnWaitTest( "Sorting multi-column - add column 1", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2'); } ); oTest.fnWaitTest( "Sorting multi-column - add column 2", function () { oDispacher.click( $('#example thead th:eq(2)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3'); } ); oTest.fnWaitTest( "Sorting multi-column - add column 3", function () { oDispacher.click( $('#example thead th:eq(3)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') && $('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3'); } ); oTest.fnWaitTest( "Remove sorting classes on single column sort", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') == false && $('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3') == false; } ); oTest.fnWaitTest( "Sorting class 1 was added", null, function () { return $('#example tbody tr:eq(1) td:eq(4)').hasClass('sorting_1'); } ); /* Check can disable */ oTest.fnWaitTest( "Sorting classes can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bSortClasses": false } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false; } ); oTest.fnWaitTest( "Sorting classes disabled - add column 1 - no effect", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false; } ); oTest.fnWaitTest( "Sorting classes disabled - add column 2 - no effect", function () { oDispacher.click( $('#example thead th:eq(2)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') == false; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Sorting classes enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bSortClasses": true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'); } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.iDataSort" ); $(document).ready( function () { /* Should know that sorting already works by default from other tests, so we can jump * right in here */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "iDataSort": 4 }, null, null, null ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Sorting on first column is uneffected", null, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko'; } ); oTest.fnWaitTest( "Sorting on second column is the order of the fifth", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnWaitTest( "Reserve sorting on second column uses fifth column as well", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'X'; } ); oTest.fnWaitTest( "Sorting on 5th column retains it's own sorting", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnWaitTest( "Use 2nd col for sorting 5th col and via-versa - no effect on first col sorting", function () { mTmp = 0; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "iDataSort": 4 }, null, null, { "iDataSort": 1 } ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko'; } ); oTest.fnWaitTest( "2nd col sorting uses fifth col", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnWaitTest( "2nd col sorting uses fifth col - reversed", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'X'; } ); oTest.fnWaitTest( "5th col sorting uses 2nd col", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; } ); oTest.fnWaitTest( "5th col sorting uses 2nd col - reversed", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'Seamonkey 1.1'; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bSeachable" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Columns are searchable by default", function () { oTable.fnFilter("Camino"); }, function () { if ( $('#example tbody tr:eq(0) td:eq(1)')[0] ) return $('#example tbody tr:eq(0) td:eq(1)').html().match(/Camino/); else return null; } ); oTest.fnWaitTest( "Disabling sorting on a column removes it from the global filter", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "bSearchable": false }, null, null, null ] } ); oSettings = oTable.fnSettings(); oTable.fnFilter("Camino"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnWaitTest( "Disabled on one column has no effect on other columns", function () { oTable.fnFilter("Webkit"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Webkit"; } ); oTest.fnWaitTest( "Disable filtering on multiple columns", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ { "bSearchable": false }, { "bSearchable": false }, null, null, null ] } ); oSettings = oTable.fnSettings(); oTable.fnFilter("Webkit"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnWaitTest( "Filter on second disabled column", function () { oTable.fnFilter("Camino"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bVisible" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "All columns are visible by default", null, function () { return $('#example tbody tr:eq(0) td').length == 5; } ); oTest.fnWaitTest( "Can hide one column and it removes td column from DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "bVisible": false }, null, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td').length == 4; } ); oTest.fnWaitTest( "Can hide one column and it removes thead th column from DOM", null, function () { return $('#example thead tr:eq(0) th').length == 4; } ); oTest.fnWaitTest( "The correct thead column has been hidden", null, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "Platform(s)" && jqNodes[2].innerHTML == "Engine version" && jqNodes[3].innerHTML == "CSS grade"; return bReturn; } ); oTest.fnWaitTest( "The correct tbody column has been hidden", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var jqNodes = $('#example tbody tr:eq(0) td'); var bReturn = jqNodes[0].innerHTML == "Gecko" && jqNodes[1].innerHTML == "Gnome" && jqNodes[2].innerHTML == "1.8" && jqNodes[3].innerHTML == "A"; return bReturn; } ); oTest.fnWaitTest( "Can hide multiple columns and it removes td column from DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "aoColumns": [ null, { "bVisible": false }, { "bVisible": false }, null, { "bVisible": false } ] } ); }, function () { return $('#example tbody tr:eq(0) td').length == 2; } ); oTest.fnWaitTest( "Multiple hide - removes thead th column from DOM", null, function () { return $('#example thead tr:eq(0) th').length == 2; } ); oTest.fnWaitTest( "Multiple hide - the correct thead columns have been hidden", null, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "Engine version" return bReturn; } ); oTest.fnWaitTest( "Multiple hide - the correct tbody columns have been hidden", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var jqNodes = $('#example tbody tr:eq(0) td'); var bReturn = jqNodes[0].innerHTML == "Gecko" && jqNodes[1].innerHTML == "1" return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bProcessing" ); /* It's actually a bit hard to set this one due to the fact that it will only be shown * when DataTables is doing some kind of processing. The server-side processing is a bit * better to test this than here - so we just the interal functions to enable it and check * that it is available */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Processing is off by default", null, function () { return oSettings.oFeatures.bProcessing == false; } ); oTest.fnWaitTest( "Processing div is not in the DOM", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "Processing div cannot be shown", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "Processing div cannot be hidden", function () { oTable.oApi._fnProcessingDisplay( oSettings, false ); }, function () { return document.getElementById('example_processing') == null; } ); /* Check can disable */ oTest.fnWaitTest( "Processing can be enabled", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bProcessing": true } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bProcessing == true; } ); oTest.fnWaitTest( "Processing div is in the DOM", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing'); } ); oTest.fnWaitTest( "Processing div is hidden by default", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing').style.visibility = "hidden"; } ); oTest.fnWaitTest( "Processing div can be shown", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing').style.visibility = "visible"; } ); oTest.fnWaitTest( "Processing div can be hidden", function () { oTable.oApi._fnProcessingDisplay( oSettings, false ); }, function () { return document.getElementById('example_processing').style.visibility = "hidden"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Processing disabled override", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "bProcessing": false } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bProcessing == false; } ); oTest.fnWaitTest( "Processing div is not in the DOM", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing') == null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sInfoPostFix" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Info post fix language is '' (blank) by default", null, function () { return oSettings.oLanguage.sInfoPostFix == ""; } ); oTest.fnTest( "Width no post fix, the basic info shows", null, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries"; } ); oTest.fnWaitTest( "Info post fix language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfoPostFix": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sInfoPostFix == "unit test"; } ); oTest.fnTest( "Info empty language default is in the DOM", null, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries unit test"; } ); oTest.fnWaitTest( "Macros have no effect in the post fix", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfoPostFix": "unit _START_ _END_ _TOTAL_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries unit _START_ _END_ _TOTAL_ test"; } ); oTest.fnWaitTest( "Post fix is applied after fintering info", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfoPostFix": "unit test" } } ); oTable.fnFilter("nothinghere"); }, function () { return document.getElementById('example_info').innerHTML = "Showing 0 to 0 of 0 entries unit (filtered from 57 total entries) test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "asStripeClasses" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); oTest.fnWaitTest( "Default row striping is applied", null, function () { return $('#example tbody tr:eq(0)').hasClass('odd') && $('#example tbody tr:eq(1)').hasClass('even') && $('#example tbody tr:eq(2)').hasClass('odd') && $('#example tbody tr:eq(3)').hasClass('even'); } ); oTest.fnWaitTest( "Row striping on the second page", function () { $('#example_next').click(); }, function () { return $('#example tbody tr:eq(0)').hasClass('odd') && $('#example tbody tr:eq(1)').hasClass('even') && $('#example tbody tr:eq(2)').hasClass('odd') && $('#example tbody tr:eq(3)').hasClass('even'); } ); /* No striping */ oTest.fnWaitTest( "No row striping", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "asStripeClasses": [] } ); }, function () { if ( typeof $('#example tbody tr:eq(1)')[0] == 'undefined' ) { /* Use the 'wait for' to allow this to become true */ return false; } return $('#example tbody tr:eq(0)')[0].className == "" && $('#example tbody tr:eq(1)')[0].className == "" && $('#example tbody tr:eq(2)')[0].className == "" && $('#example tbody tr:eq(3)')[0].className == ""; } ); /* Custom striping */ oTest.fnWaitTest( "Custom striping [2]", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "asStripeClasses": [ 'test1', 'test2' ] } ); }, function () { return $('#example tbody tr:eq(0)').hasClass('test1') && $('#example tbody tr:eq(1)').hasClass('test2') && $('#example tbody tr:eq(2)').hasClass('test1') && $('#example tbody tr:eq(3)').hasClass('test2'); } ); /* long array of striping */ oTest.fnWaitTest( "Custom striping [4]", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "asStripeClasses": [ 'test1', 'test2', 'test3', 'test4' ] } ); }, function () { return $('#example tbody tr:eq(0)').hasClass('test1') && $('#example tbody tr:eq(1)').hasClass('test2') && $('#example tbody tr:eq(2)').hasClass('test3') && $('#example tbody tr:eq(3)').hasClass('test4'); } ); oTest.fnWaitTest( "Custom striping is restarted on second page [2]", function () { $('#example_next').click(); }, function () { return $('#example tbody tr:eq(0)').hasClass('test1') && $('#example tbody tr:eq(1)').hasClass('test2') && $('#example tbody tr:eq(2)').hasClass('test3') && $('#example tbody tr:eq(3)').hasClass('test4'); } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bServerSide" ); /* Not interested in server-side processing here other than to check that it is off */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Server side is off by default", null, function () { return oSettings.oFeatures.bServerSide == false; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "sDom" ); /* This is going to be brutal on the browser! There is a lot that can be tested here... */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default DOM varaible", null, function () { return oSettings.sDom == "lfrtip"; } ); oTest.fnWaitTest( "Default DOM in document", null, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && nNodes[2] == nFilter && nNodes[3] == nTable && nNodes[4] == nInfo && nNodes[5] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check example 1 in code propagates", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sDom": '<"wrapper"flipt>' } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.sDom == '<"wrapper"flipt>'; } ); oTest.fnWaitTest( "Check example 1 in DOM", null, function () { var jqNodes = $('#demo div, #demo table'); var nNodes = []; /* Strip the paging nodes */ for ( var i=0, iLen=jqNodes.length ; i<iLen ; i++ ) { if ( jqNodes[i].getAttribute('id') != "example_previous" && jqNodes[i].getAttribute('id') != "example_next" ) { nNodes.push( jqNodes[i] ); } } var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var nCustomWrapper = $('div.wrapper')[0]; var bReturn = nNodes[0] == nWrapper && nNodes[1] == nCustomWrapper && nNodes[2] == nFilter && nNodes[3] == nLength && nNodes[4] == nInfo && nNodes[5] == nPaging && nNodes[6] == nTable; return bReturn; } ); oTest.fnWaitTest( "Check example 2 in DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sDom": '<lf<t>ip>' } ); }, function () { var jqNodes = $('#demo div, #demo table'); var nNodes = []; var nCustomWrappers = [] /* Strip the paging nodes */ for ( var i=0, iLen=jqNodes.length ; i<iLen ; i++ ) { if ( jqNodes[i].getAttribute('id') != "example_previous" && jqNodes[i].getAttribute('id') != "example_next" ) { nNodes.push( jqNodes[i] ); } /* Only the two custom divs don't have class names */ if ( jqNodes[i].className == "" ) { nCustomWrappers.push( jqNodes[i] ); } } var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nCustomWrappers[0] && nNodes[2] == nLength && nNodes[3] == nFilter && nNodes[4] == nCustomWrappers[1] && nNodes[5] == nTable && nNodes[6] == nInfo && nNodes[7] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check no length element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sDom": 'frtip' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && null == nLength && nNodes[1] == nFilter && nNodes[2] == nTable && nNodes[3] == nInfo && nNodes[4] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check no filter element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sDom": 'lrtip' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && null == nFilter && nNodes[2] == nTable && nNodes[3] == nInfo && nNodes[4] == nPaging; return bReturn; } ); /* Note we don't test for no table as this is not supported (and it would be fairly daft! */ oTest.fnWaitTest( "Check no info element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sDom": 'lfrtp' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && nNodes[2] == nFilter && nNodes[3] == nTable && null == nInfo && nNodes[4] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check no paging element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sDom": 'lfrti' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && nNodes[2] == nFilter && nNodes[3] == nTable && nNodes[4] == nInfo && null == nPaging; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Custom data source property - array only" ); $(document).ready( function () { var oInit = { "sAjaxSource": "../../../examples/ajax/sources/array_only.txt", "sAjaxDataProp": "" }; $('#example').dataTable( oInit ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnHeaderCallback" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); var mPass, bInit; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnHeaderCallback == null; } ); oTest.fnWaitTest( "Five arguments passed", function () { oSession.fnRestore(); mPass = -1; bInit = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( ) { mPass = arguments.length; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return mPass == 5 && bInit; } ); /* The header callback is called once for the init and then when the data is added */ oTest.fnWaitTest( "fnHeaderCallback called once per draw", function () { oSession.fnRestore(); mPass = 0; bInit = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { mPass++; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return mPass == 2 && bInit; } ); oTest.fnWaitTest( "fnRowCallback called on paging (i.e. another draw)", function () { $('#example_next').click(); }, function () { return mPass == 3; } ); oTest.fnWaitTest( "fnRowCallback allows us to alter row information", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records"; } } ); }, function () { return $('#example thead th:eq(0)').html() == "Displaying 10 records"; } ); oTest.fnWaitTest( "iStart correct on first page", function () { oSession.fnRestore(); mPass = true; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { if ( iStart != 0 ) { mPass = false; } } } ); }, function () { return mPass; } ); oTest.fnWaitTest( "iStart correct on second page", function () { oSession.fnRestore(); mPass = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { if ( iStart == 10 ) { mPass = true; } }, "fnInitComplete": function () { $('#example_next').click(); } } ); }, function () { return mPass; } ); oTest.fnWaitTest( "iEnd correct on second page", function () { oSession.fnRestore(); mPass = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { if ( iEnd == 20 ) { mPass = true; } }, "fnInitComplete": function () { $('#example_next').click(); } } ); }, function () { return mPass; } ); oTest.fnWaitTest( "aiDisplay length is full data when not filtered", function () { oSession.fnRestore(); mPass = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { if ( aiDisplay.length == 57 ) { mPass = true; } } } ); }, function () { return mPass; } ); oTest.fnWaitTest( "aiDisplay length is 9 when filtering on 'Mozilla'", function () { oSession.fnRestore(); mPass = false; oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) { if ( aiDisplay.length == 9 ) { mPass = true; } } } ); oTable.fnFilter( "Mozilla" ); }, function () { return mPass; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "sPaginationType" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Check two button paging is the default", null, function () { return oSettings.sPaginationType == "two_button"; } ); oTest.fnWaitTest( "Check class is applied", null, function () { return $('#example_paginate').hasClass('paging_two_button'); } ); oTest.fnWaitTest( "Two A elements are in the wrapper", null, function () { return $('#example_paginate a').length == 2; } ); oTest.fnWaitTest( "We have the previous button", null, function () { return document.getElementById('example_previous'); } ); oTest.fnWaitTest( "We have the next button", null, function () { return document.getElementById('example_next'); } ); oTest.fnWaitTest( "Previous button is disabled", null, function () { return $('#example_previous').hasClass('paginate_disabled_previous'); } ); oTest.fnWaitTest( "Next button is enabled", null, function () { return $('#example_next').hasClass('paginate_enabled_next'); } ); /* Don't test paging - that's done by the zero config test script. */ /* Two buttons paging */ var bComplete = false; oTest.fnWaitTest( "Can enabled full numbers paging", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "sPaginationType": "full_numbers", "fnInitComplete": function () { bComplete = true; } } ); oSettings = oTable.fnSettings(); }, function () { if ( bComplete ) return oSettings.sPaginationType == "full_numbers"; else return false; } ); oTest.fnWaitTest( "Check full numbers class is applied", null, function () { return $('#example_paginate').hasClass('paging_full_numbers'); } ); var nFirst, nPrevious, nNext, nLast; oTest.fnWaitTest( "Jump to last page", function () { nFirst = $('div.dataTables_paginate a.first'); nPrevious = $('div.dataTables_paginate a.previous'); nNext = $('div.dataTables_paginate a.next'); nLast = $('div.dataTables_paginate a.last'); nLast.click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnWaitTest( "Go to two pages previous", function () { nPrevious.click(); nPrevious.click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 40 of 57 entries"; } ); oTest.fnWaitTest( "Next (second last) page", function () { nNext.click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 41 to 50 of 57 entries"; } ); oTest.fnWaitTest( "Jump to first page", function () { nFirst.click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sInfoEmpty" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Info empty language is 'Showing 0 to 0 of 0 entries' by default", function () { oTable.fnFilter("nothinghere"); }, function () { return oSettings.oLanguage.sInfoEmpty == "Showing 0 to 0 of 0 entries"; } ); oTest.fnTest( "Info empty language default is in the DOM", null, function () { var bReturn = document.getElementById('example_info').innerHTML.replace( ' '+oSettings.oLanguage.sInfoFiltered.replace( '_MAX_', '57' ), "" ) == "Showing 0 to 0 of 0 entries"; return bReturn; } ); oTest.fnWaitTest( "Info empty language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfoEmpty": "unit test" } } ); oSettings = oTable.fnSettings(); oTable.fnFilter("nothinghere"); }, function () { return oSettings.oLanguage.sInfoEmpty == "unit test"; } ); oTest.fnTest( "Info empty language default is in the DOM", null, function () { var bReturn = document.getElementById('example_info').innerHTML.replace( ' '+oSettings.oLanguage.sInfoFiltered.replace( '_MAX_', '57' ), "" ) == "unit test"; return bReturn; } ); oTest.fnWaitTest( "Macro's replaced", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfoEmpty": "unit _START_ _END_ _TOTAL_ test" } } ); oTable.fnFilter("nothinghere"); }, function () { var bReturn = document.getElementById('example_info').innerHTML.replace( ' '+oSettings.oLanguage.sInfoFiltered.replace( '_MAX_', '57' ), "" ) == "unit 1 0 0 test"; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sLengthMenu" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Menu language is 'Show _MENU_ entries' by default", null, function () { return oSettings.oLanguage.sLengthMenu == "Show _MENU_ entries"; } ); oTest.fnTest( "_MENU_ macro is replaced by select menu in DOM", null, function () { return $('select', oSettings.aanFeatures.l[0]).length == 1 } ); oTest.fnTest( "A label input is used", null, function () { return $('label', oSettings.aanFeatures.l[0]).length == 1 } ); oTest.fnTest( "Default is put into DOM", null, function () { var anChildren = $('label',oSettings.aanFeatures.l[0])[0].childNodes; var bReturn = anChildren[0].nodeValue == "Show " && anChildren[2].nodeValue == " entries"; return bReturn; } ); oTest.fnWaitTest( "Menu length language can be defined - no _MENU_ macro", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sLengthMenu": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sLengthMenu == "unit test"; } ); oTest.fnTest( "Menu length language definition is in the DOM", null, function () { return $('label', oSettings.aanFeatures.l[0]).text() == "unit test"; } ); oTest.fnWaitTest( "Menu length language can be defined - with _MENU_ macro", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sLengthMenu": "unit _MENU_ test" } } ); oSettings = oTable.fnSettings(); }, function () { var anChildren = $('label',oSettings.aanFeatures.l[0])[0].childNodes; var bReturn = anChildren[0].nodeValue == "unit " && anChildren[2].nodeValue == " test"; return bReturn; } ); oTest.fnWaitTest( "Only the _MENU_ macro", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sLengthMenu": "_MENU_" } } ); oSettings = oTable.fnSettings(); }, function () { var anChildren = oSettings.aanFeatures.l[0].childNodes; var bReturn = anChildren.length == 1 && $('select', oSettings.aanFeatures.l[0]).length == 1; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sInfo" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Info language is 'Showing _START_ to _END_ of _TOTAL_ entries' by default", null, function () { return oSettings.oLanguage.sInfo == "Showing _START_ to _END_ of _TOTAL_ entries"; } ); oTest.fnTest( "Info language default is in the DOM", null, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries"; } ); oTest.fnWaitTest( "Info language can be defined - without any macros", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfo": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sInfo == "unit test"; } ); oTest.fnTest( "Info language definition is in the DOM", null, function () { return document.getElementById('example_info').innerHTML = "unit test"; } ); oTest.fnWaitTest( "Info language can be defined - with macro _START_ only", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfo": "unit _START_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "unit 1 test"; } ); oTest.fnWaitTest( "Info language can be defined - with macro _END_ only", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfo": "unit _END_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "unit 10 test"; } ); oTest.fnWaitTest( "Info language can be defined - with macro _TOTAL_ only", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfo": "unit _END_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "unit 57 test"; } ); oTest.fnWaitTest( "Info language can be defined - with macros _START_ and _END_", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfo": "unit _START_ _END_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "unit 1 10 test"; } ); oTest.fnWaitTest( "Info language can be defined - with macros _START_, _END_ and _TOTAL_", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/arrays.txt", "oLanguage": { "sInfo": "unit _START_ _END_ _TOTAL_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "unit 1 10 57 test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Custom data source property - property given" ); $(document).ready( function () { var oInit = { "sAjaxSource": "../../../examples/ajax/sources/custom_prop.txt", "sAjaxDataProp": "demo" }; $('#example').dataTable( oInit ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sClass" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "By default the test class hasn't been applied to the column (sanity!)", null, function () { return $('#example tbody tr:eq(0) td:eq(2)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - first row", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform", "sClass": 'unittest' }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return $('#example tbody tr:eq(1) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - third row", null, function () { return $('#example tbody tr:eq(3) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - last row", null, function () { return $('#example tbody tr:eq(9) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to other columns - 1st", null, function () { return $('#example tbody tr:eq(3) td:eq(0)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to other columns - 5th", null, function () { return $('#example tbody tr:eq(3) td:eq(4)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - seventh row - second page", function () { $('#example_next').click(); }, function () { return $('#example tbody tr:eq(6) td:eq(2)').hasClass('unittest'); } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to header", null, function () { return $('#example thead tr:eq(3) th:eq(4)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Add a class to a single column - has not applied to footer", null, function () { return $('#example thead tr:eq(3) th:eq(4)').hasClass('unittest') == false; } ); oTest.fnWaitTest( "Class defined for multiple columns - first row", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine", "sClass": 'unittest2' }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version", "sClass": 'unittest1' }, { "mData": "grade" } ] } ); }, function () { var bReturn = $('#example tbody tr:eq(3) td:eq(0)').hasClass('unittest2') && $('#example tbody tr:eq(8) td:eq(3)').hasClass('unittest1'); return bReturn; } ); oTest.fnWaitTest( "Class defined for multiple columns - has not applied to other columns - 5th 1", null, function () { return $('#example tbody tr:eq(0) td:eq(4)').hasClass('unittest1') == false; } ); oTest.fnWaitTest( "Class defined for multiple columns - has not applied to other columns - 5th 2", null, function () { return $('#example tbody tr:eq(6) td:eq(4)').hasClass('unittest2') == false; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aaSorting" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default sorting is single column", null, function () { return oSettings.aaSorting.length == 1 && typeof oSettings.aaSorting[0] == 'object'; } ); oTest.fnWaitTest( "Default sorting is first column asc", null, function () { return oSettings.aaSorting[0].length == 3 && oSettings.aaSorting[0][0] == 0 && oSettings.aaSorting[0][1] == 'asc'; } ); oTest.fnWaitTest( "Sorting is applied", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnWaitTest( "Custom sorting on single string column asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Custom sorting on single string column desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Custom sorting on single int column asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['1','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnWaitTest( "Custom sorting on single int column desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','asc'], ['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Camino 1.0"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / string desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','asc'], ['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','desc'], ['1','asc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "iPod Touch / iPhone"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / string desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','desc'], ['1','desc']] } ); }, function () { return $('#example tbody td:eq(1)').html() == "Safari 3.0"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / int asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','asc'], ['3','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "1"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string asc / int desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','asc'], ['3','desc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "1.9"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / int asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','desc'], ['3','asc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "125.5"; } ); oTest.fnWaitTest( "Multi-column sorting (2 column) - string desc / int desc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','desc'], ['3','desc']] } ); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnWaitTest( "Multi-column sorting (3 column) - string asc / int asc / string asc", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSorting": [['0','asc'], ['3','asc'], ['1','asc']] } ); }, function () { return $('#example tbody tr:eq(7) td:eq(1)').html() == "Firefox 1.0"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoSearchCols" ); /* We could be here forever testing this one, so we test a limited subset on a couple of colums */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default should be to have a empty colums array", null, function () { var bReturn = oSettings.aoPreSearchCols[0].sSearch == 0 && !oSettings.aoPreSearchCols[0].bRegex && oSettings.aoPreSearchCols[1].sSearch == 0 && !oSettings.aoPreSearchCols[1].bRegex && oSettings.aoPreSearchCols[2].sSearch == 0 && !oSettings.aoPreSearchCols[2].bRegex && oSettings.aoPreSearchCols[3].sSearch == 0 && !oSettings.aoPreSearchCols[3].bRegex && oSettings.aoPreSearchCols[4].sSearch == 0 && !oSettings.aoPreSearchCols[4].bRegex; return bReturn; } ); oTest.fnWaitTest( "Search on a single column - no regex statement given", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "aoSearchCols": [ null, { "sSearch": "Mozilla" }, null, { "sSearch": "1" }, null ] } ); }, function () { return $('#example_info').html() == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnWaitTest( "Search on two columns - no regex statement given", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "aoSearchCols": [ null, { "sSearch": "Mozilla" }, null, { "sSearch": "1.5" }, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "1.5"; } ); oTest.fnWaitTest( "Search on single column - escape regex false", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "aoSearchCols": [ { "sSearch": ".*ML", "bEscapeRegex": false }, null, null, null, null ] } ); }, function () { return $('#example_info').html() == "Showing 1 to 3 of 3 entries (filtered from 57 total entries)"; } ); oTest.fnWaitTest( "Search on two columns - escape regex false on first, true on second", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "aoSearchCols": [ { "sSearch": ".*ML", "bEscapeRegex": false }, { "sSearch": "3.3", "bEscapeRegex": true }, null, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Konqureror 3.3"; } ); oTest.fnWaitTest( "Search on two columns (no records) - escape regex false on first, true on second", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "aoSearchCols": [ { "sSearch": ".*ML", "bEscapeRegex": false }, { "sSearch": "Allan", "bEscapeRegex": true }, null, null, null ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aaSortingFixed" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "No fixed sorting by default", null, function () { return oSettings.aaSortingFixed == null; } ); oTest.fnWaitTest( "Fixed sorting on first column (string/asc) with user sorting on second column (string/asc)", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSortingFixed": [['0','asc']], "fnInitComplete": function () { $('#example thead th:eq(1)').click(); } } ); // }, function () { return $('#example tbody td:eq(1)').html() == "Camino 1.0"; } ); oTest.fnWaitTest( "Fixed sorting on first column (string/asc) with user sorting on second column (string/desc)", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Fixed sorting on fourth column (int/asc) with user sorting on second column (string/asc)", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaSortingFixed": [['3','asc']] } ); $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Fixed sorting on fourth column (int/asc) with user sorting on second column (string/desc)", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "PSP browser"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnInitComplete" ); /* Fairly boring function compared to the others! */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); var mPass; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnInitComplete == null; } ); oTest.fnWaitTest( "Two arguments passed (for Ajax!)", function () { oSession.fnRestore(); mPass = -1; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnInitComplete": function ( ) { mPass = arguments.length; } } ); }, function () { return mPass == 2; } ); oTest.fnWaitTest( "That one argument is the settings object", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnInitComplete": function ( oSettings ) { mPass = oSettings; } } ); }, function () { return oTable.fnSettings() == mPass; } ); oTest.fnWaitTest( "fnInitComplete called once on first draw", function () { oSession.fnRestore(); mPass = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnInitComplete": function ( ) { mPass++; } } ); }, function () { return mPass == 1; } ); oTest.fnWaitTest( "fnInitComplete never called there after", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return mPass == 1; } ); oTest.fnWaitTest( "10 rows in the table on complete", function () { oSession.fnRestore(); mPass = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnInitComplete": function ( ) { mPass = $('#example tbody tr').length; } } ); }, function () { return mPass == 10; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.fnRender" ); $(document).ready( function () { /* Check the default */ var mTmp = 0; var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "fnRender": function (a) { mTmp++; return a.aData['browser']; } }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Single column - fnRender is called twice for each row", null, function () { return mTmp == 57; } ); oTest.fnWaitTest( "Confirm that fnRender passes two arguments with four parameters", function () { mTmp = true; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "fnRender": function (a) { if ( arguments.length != 2 || typeof a.iDataRow=='undefined' || typeof a.iDataColumn=='undefined' || typeof a.aData=='undefined' || typeof a.mData=='undefined' ) { mTmp = false; } return a.aData['browser']; }, "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return mTmp; } ); oTest.fnWaitTest( "fnRender iDataColumn is the column", function () { mTmp = true; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "fnRender": function (a) { if ( a.iDataColumn != 1 ) { mTmp = false; } return a.aData['browser']; } }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return mTmp; } ); oTest.fnWaitTest( "fnRender aData is data array of correct size", function () { mTmp = true; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "fnRender": function (a) { if ( a.aData.length != 5 ) { mTmp = false; } return a.aData['browser']; } }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return mTmp; } ); oTest.fnWaitTest( "Passed back data is put into the DOM", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "fnRender": function (a) { return 'unittest'; } }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'unittest'; } ); oTest.fnWaitTest( "Passed back data is put into the DOM", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform", "fnRender": function (a) { return 'unittest1'; } }, { "mData": "version", "fnRender": function (a) { return 'unittest2'; } }, { "mData": "grade" } ] } ); }, function () { var bReturn = $('#example tbody tr:eq(0) td:eq(2)').html() == 'unittest1' && $('#example tbody tr:eq(0) td:eq(3)').html() == 'unittest2'; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sWidth" ); /* NOTE - we need to disable the auto width for the majority of these test in order to preform * these tests as the auto width will convert the width to a px value. We can do 'non-exact' tests * with auto width enabled however to ensure it scales columns as required */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "bAutoWidth": false, "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "sWidth": '40%' }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "With auto width disabled the width for one column is appled", null, function () { return $('#example thead th:eq(1)')[0].style.width == "40%"; } ); oTest.fnWaitTest( "With auto width disabled the width for one column is appled", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "bAutoWidth": false, "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform", "sWidth": '20%' }, { "mData": "version", "sWidth": '30%' }, { "mData": "grade" } ] } ); }, function () { var bReturn = $('#example thead th:eq(2)')[0].style.width == "20%" && $('#example thead th:eq(3)')[0].style.width == "30%"; return bReturn; } ); oTest.fnWaitTest( "With auto width, it will make the smallest column the largest with percentage width given", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version", "sWidth": '40%' }, { "mData": "grade" } ] } ); }, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; if ( a3>a0 && a3>a1 && a3>a2 && a3>a4 ) return true; else return false; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sName" ); /* This has no effect at all in DOM methods - so we just check that it has applied the name */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version", "sName": 'unit test' }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Names are stored in the columns object", null, function () { return oSettings.aoColumns[3].sName =="unit test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnRowCallback" ); /* Note - fnRowCallback MUST return the first arguments (modified or not) */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); var mPass; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnRowCallback == null; } ); oTest.fnWaitTest( "Four arguments passed", function () { oSession.fnRestore(); mPass = -1; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnRowCallback": function ( nTr ) { mPass = arguments.length; return nTr; } } ); }, function () { return mPass == 4; } ); oTest.fnWaitTest( "fnRowCallback called once for each drawn row", function () { oSession.fnRestore(); mPass = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { mPass++; return nTr; } } ); }, function () { return mPass == 10; } ); oTest.fnWaitTest( "fnRowCallback allows us to alter row information", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { $(nTr).addClass('unit_test'); return nTr; } } ); }, function () { return $('#example tbody tr:eq(1)').hasClass('unit_test'); } ); oTest.fnWaitTest( "Data array has length matching columns", function () { oSession.fnRestore(); mPass = true; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { if ( asData.length != 5 ) mPass = false; return nTr; } } ); }, function () { return mPass; } ); oTest.fnWaitTest( "Data array has length matching columns", function () { oSession.fnRestore(); mPass = true; var iCount = 0; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnRowCallback": function ( nTr, asData, iDrawIndex, iDataIndex ) { if ( iCount != iDrawIndex ) mPass = false; iCount++; return nTr; } } ); }, function () { return mPass; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS - Deep data source" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform.inner" }, { "mData": "platform.details.0" }, { "mData": "platform.details.1" } ], "aaData": [ { "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": { "inner": "Win 95+", "details": [ "4", "X" ] } }, { "engine": "Trident", "browser": "Internet Explorer 5.0", "platform": { "inner": "Win 95+", "details": [ "5", "C" ] } }, { "engine": "Trident", "browser": "Internet Explorer 5.5", "platform": { "inner": "Win 95+", "details": [ "5.5", "A" ] } }, { "engine": "Trident", "browser": "Internet Explorer 6", "platform": { "inner": "Win 98+", "details": [ "6", "A" ] } }, { "engine": "Trident", "browser": "Internet Explorer 7", "platform": { "inner": "Win XP SP2+", "details": [ "7", "A" ] } }, { "engine": "Trident", "browser": "AOL browser (AOL desktop)", "platform": { "inner": "Win XP", "details": [ "6", "A" ] } }, { "engine": "Gecko", "browser": "Firefox 1.0", "platform": { "inner": "Win 98+ / OSX.2+", "details": [ "1.7", "A" ] } }, { "engine": "Gecko", "browser": "Firefox 1.5", "platform": { "inner": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] } }, { "engine": "Gecko", "browser": "Firefox 2.0", "platform": { "inner": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] } }, { "engine": "Gecko", "browser": "Firefox 3.0", "platform": { "inner": "Win 2k+ / OSX.3+", "details": [ "1.9", "A" ] } }, { "engine": "Gecko", "browser": "Camino 1.0", "platform": { "inner": "OSX.2+", "details": [ "1.8", "A" ] } }, { "engine": "Gecko", "browser": "Camino 1.5", "platform": { "inner": "OSX.3+", "details": [ "1.8", "A" ] } }, { "engine": "Gecko", "browser": "Netscape 7.2", "platform": { "inner": "Win 95+ / Mac OS 8.6-9.2", "details": [ "1.7", "A" ] } }, { "engine": "Gecko", "browser": "Netscape Browser 8", "platform": { "inner": "Win 98SE+", "details": [ "1.7", "A" ] } }, { "engine": "Gecko", "browser": "Netscape Navigator 9", "platform": { "inner": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.0", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.1", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1.1, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.2", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1.2, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.3", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1.3, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.4", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1.4, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.5", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1.5, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.6", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ 1.6, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.7", "platform": { "inner": "Win 98+ / OSX.1+", "details": [ 1.7, "A" ] } }, { "engine": "Gecko", "browser": "Mozilla 1.8", "platform": { "inner": "Win 98+ / OSX.1+", "details": [ 1.8, "A" ] } }, { "engine": "Gecko", "browser": "Seamonkey 1.1", "platform": { "inner": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] } }, { "engine": "Gecko", "browser": "Epiphany 2.20", "platform": { "inner": "Gnome", "details": [ "1.8", "A" ] } }, { "engine": "Webkit", "browser": "Safari 1.2", "platform": { "inner": "OSX.3", "details": [ "125.5", "A" ] } }, { "engine": "Webkit", "browser": "Safari 1.3", "platform": { "inner": "OSX.3", "details": [ "312.8", "A" ] } }, { "engine": "Webkit", "browser": "Safari 2.0", "platform": { "inner": "OSX.4+", "details": [ "419.3", "A" ] } }, { "engine": "Webkit", "browser": "Safari 3.0", "platform": { "inner": "OSX.4+", "details": [ "522.1", "A" ] } }, { "engine": "Webkit", "browser": "OmniWeb 5.5", "platform": { "inner": "OSX.4+", "details": [ "420", "A" ] } }, { "engine": "Webkit", "browser": "iPod Touch / iPhone", "platform": { "inner": "iPod", "details": [ "420.1", "A" ] } }, { "engine": "Webkit", "browser": "S60", "platform": { "inner": "S60", "details": [ "413", "A" ] } }, { "engine": "Presto", "browser": "Opera 7.0", "platform": { "inner": "Win 95+ / OSX.1+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera 7.5", "platform": { "inner": "Win 95+ / OSX.2+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera 8.0", "platform": { "inner": "Win 95+ / OSX.2+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera 8.5", "platform": { "inner": "Win 95+ / OSX.2+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera 9.0", "platform": { "inner": "Win 95+ / OSX.3+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera 9.2", "platform": { "inner": "Win 88+ / OSX.3+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera 9.5", "platform": { "inner": "Win 88+ / OSX.3+", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Opera for Wii", "platform": { "inner": "Wii", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Nokia N800", "platform": { "inner": "N800", "details": [ "-", "A" ] } }, { "engine": "Presto", "browser": "Nintendo DS browser", "platform": { "inner": "Nintendo DS", "details": [ "8.5", "C/A<sup>1</sup>" ] } }, { "engine": "KHTML", "browser": "Konqureror 3.1", "platform": { "inner": "KDE 3.1", "details": [ "3.1", "C" ] } }, { "engine": "KHTML", "browser": "Konqureror 3.3", "platform": { "inner": "KDE 3.3", "details": [ "3.3", "A" ] } }, { "engine": "KHTML", "browser": "Konqureror 3.5", "platform": { "inner": "KDE 3.5", "details": [ "3.5", "A" ] } }, { "engine": "Tasman", "browser": "Internet Explorer 4.5", "platform": { "inner": "Mac OS 8-9", "details": [ "-", "X" ] } }, { "engine": "Tasman", "browser": "Internet Explorer 5.1", "platform": { "inner": "Mac OS 7.6-9", "details": [ "1", "C" ] } }, { "engine": "Tasman", "browser": "Internet Explorer 5.2", "platform": { "inner": "Mac OS 8-X", "details": [ "1", "C" ] } }, { "engine": "Misc", "browser": "NetFront 3.1", "platform": { "inner": "Embedded devices", "details": [ "-", "C" ] } }, { "engine": "Misc", "browser": "NetFront 3.4", "platform": { "inner": "Embedded devices", "details": [ "-", "A" ] } }, { "engine": "Misc", "browser": "Dillo 0.8", "platform": { "inner": "Embedded devices", "details": [ "-", "X" ] } }, { "engine": "Misc", "browser": "Links", "platform": { "inner": "Text only", "details": [ "-", "X" ] } }, { "engine": "Misc", "browser": "Lynx", "platform": { "inner": "Text only", "details": [ "-", "X" ] } }, { "engine": "Misc", "browser": "IE Mobile", "platform": { "inner": "Windows Mobile 6", "details": [ "-", "C" ] } }, { "engine": "Misc", "browser": "PSP browser", "platform": { "inner": "PSP", "details": [ "-", "C" ] } }, { "engine": "Other browsers", "browser": "All others", "platform": { "inner": "-", "details": [ "-", "U" ] } } ] }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.sTitle" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "If not given, then the columns titles are empty", null, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "Browser" && jqNodes[2].innerHTML == "Platform(s)" && jqNodes[3].innerHTML == "Engine version" && jqNodes[4].innerHTML == "CSS grade"; return bReturn; } ); oTest.fnWaitTest( "Can set a single column title - and others are read from DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "sTitle": 'unit test' }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "unit test" && jqNodes[2].innerHTML == "Platform(s)" && jqNodes[3].innerHTML == "Engine version" && jqNodes[4].innerHTML == "CSS grade"; return bReturn; } ); oTest.fnWaitTest( "Can set multiple column titles", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "sTitle": 'unit test 1' }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade", "sTitle": 'unit test 2' } ] } ); }, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "unit test 1" && jqNodes[2].innerHTML == "Platform(s)" && jqNodes[3].innerHTML == "Engine version" && jqNodes[4].innerHTML == "unit test 2"; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "iDisplayLength" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Default length is ten", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnWaitTest( "Select menu shows 10", null, function () { return $('#example_length select').val() == 10; } ); oTest.fnWaitTest( "Set initial length to 25", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "iDisplayLength": 25 } ); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnWaitTest( "Select menu shows 25", null, function () { return $('#example_length select').val() == 25; } ); oTest.fnWaitTest( "Set initial length to 100", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "iDisplayLength": 100 } ); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnWaitTest( "Select menu shows 25", null, function () { return $('#example_length select').val() == 100; } ); oTest.fnWaitTest( "Set initial length to 23 (unknown select menu length)", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "iDisplayLength": 23 } ); }, function () { return $('#example tbody tr').length == 23; } ); oTest.fnWaitTest( "Select menu shows 10 (since 23 is unknow)", null, function () { return $('#example_length select').val() == 10; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bFilter" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Filtering div exists by default", null, function () { return document.getElementById('example_filter') != null; } ); /* Check can disable */ oTest.fnWaitTest( "Fltering can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bFilter": false } ); }, function () { return document.getElementById('example_filter') == null; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Filtering enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bFilter": true } ); }, function () { return document.getElementById('example_filter') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS - Object data source" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaData": [ { "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "4", "grade": "X" }, { "engine": "Trident", "browser": "Internet Explorer 5.0", "platform": "Win 95+", "version": "5", "grade": "C" }, { "engine": "Trident", "browser": "Internet Explorer 5.5", "platform": "Win 95+", "version": "5.5", "grade": "A" }, { "engine": "Trident", "browser": "Internet Explorer 6", "platform": "Win 98+", "version": "6", "grade": "A" }, { "engine": "Trident", "browser": "Internet Explorer 7", "platform": "Win XP SP2+", "version": "7", "grade": "A" }, { "engine": "Trident", "browser": "AOL browser (AOL desktop)", "platform": "Win XP", "version": "6", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 1.0", "platform": "Win 98+ / OSX.2+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 1.5", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 2.0", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 3.0", "platform": "Win 2k+ / OSX.3+", "version": "1.9", "grade": "A" }, { "engine": "Gecko", "browser": "Camino 1.0", "platform": "OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Camino 1.5", "platform": "OSX.3+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape 7.2", "platform": "Win 95+ / Mac OS 8.6-9.2", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape Browser 8", "platform": "Win 98SE+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape Navigator 9", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.0", "platform": "Win 95+ / OSX.1+", "version": "1", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.1", "platform": "Win 95+ / OSX.1+", "version": "1.1", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.2", "platform": "Win 95+ / OSX.1+", "version": "1.2", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.3", "platform": "Win 95+ / OSX.1+", "version": "1.3", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.4", "platform": "Win 95+ / OSX.1+", "version": "1.4", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.5", "platform": "Win 95+ / OSX.1+", "version": "1.5", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.6", "platform": "Win 95+ / OSX.1+", "version": "1.6", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.7", "platform": "Win 98+ / OSX.1+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.8", "platform": "Win 98+ / OSX.1+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Seamonkey 1.1", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Epiphany 2.20", "platform": "Gnome", "version": "1.8", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 1.2", "platform": "OSX.3", "version": "125.5", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 1.3", "platform": "OSX.3", "version": "312.8", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 2.0", "platform": "OSX.4+", "version": "419.3", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 3.0", "platform": "OSX.4+", "version": "522.1", "grade": "A" }, { "engine": "Webkit", "browser": "OmniWeb 5.5", "platform": "OSX.4+", "version": "420", "grade": "A" }, { "engine": "Webkit", "browser": "iPod Touch / iPhone", "platform": "iPod", "version": "420.1", "grade": "A" }, { "engine": "Webkit", "browser": "S60", "platform": "S60", "version": "413", "grade": "A" }, { "engine": "Presto", "browser": "Opera 7.0", "platform": "Win 95+ / OSX.1+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 7.5", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 8.0", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 8.5", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.0", "platform": "Win 95+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.2", "platform": "Win 88+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.5", "platform": "Win 88+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera for Wii", "platform": "Wii", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Nokia N800", "platform": "N800", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Nintendo DS browser", "platform": "Nintendo DS", "version": "8.5", "grade": "C/A<sup>1</sup>" }, { "engine": "KHTML", "browser": "Konqureror 3.1", "platform": "KDE 3.1", "version": "3.1", "grade": "C" }, { "engine": "KHTML", "browser": "Konqureror 3.3", "platform": "KDE 3.3", "version": "3.3", "grade": "A" }, { "engine": "KHTML", "browser": "Konqureror 3.5", "platform": "KDE 3.5", "version": "3.5", "grade": "A" }, { "engine": "Tasman", "browser": "Internet Explorer 4.5", "platform": "Mac OS 8-9", "version": "-", "grade": "X" }, { "engine": "Tasman", "browser": "Internet Explorer 5.1", "platform": "Mac OS 7.6-9", "version": "1", "grade": "C" }, { "engine": "Tasman", "browser": "Internet Explorer 5.2", "platform": "Mac OS 8-X", "version": "1", "grade": "C" }, { "engine": "Misc", "browser": "NetFront 3.1", "platform": "Embedded devices", "version": "-", "grade": "C" }, { "engine": "Misc", "browser": "NetFront 3.4", "platform": "Embedded devices", "version": "-", "grade": "A" }, { "engine": "Misc", "browser": "Dillo 0.8", "platform": "Embedded devices", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "Links", "platform": "Text only", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "Lynx", "platform": "Text only", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "IE Mobile", "platform": "Windows Mobile 6", "version": "-", "grade": "C" }, { "engine": "Misc", "browser": "PSP browser", "platform": "PSP", "version": "-", "grade": "C" }, { "engine": "Other browsers", "browser": "All others", "platform": "-", "version": "-", "grade": "U" } ] }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sSearch" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Search language is 'Search:' by default", null, function () { return oSettings.oLanguage.sSearch == "Search:"; } ); oTest.fnTest( "A label input is used", null, function () { return $('label', oSettings.aanFeatures.f[0]).length == 1 } ); oTest.fnTest( "Search language default is in the DOM", null, function () { return $('label', oSettings.aanFeatures.f[0]).text() == "Search: "; } ); oTest.fnWaitTest( "Search language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sSearch": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sSearch == "unit test"; } ); oTest.fnTest( "Info language definition is in the DOM", null, function () { return $('label', oSettings.aanFeatures.f[0]).text().indexOf('unit test') !== -1; } ); oTest.fnWaitTest( "Blank search has a no space (separator) inserted", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sSearch": "" } } ); oSettings = oTable.fnSettings(); }, function () { return document.getElementById('example_filter').childNodes.length == 1; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bPaginate" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Pagiantion div exists by default", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnWaitTest( "Information div takes paging into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* Check can disable */ oTest.fnWaitTest( "Pagiantion can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bPaginate": false } ); }, function () { return document.getElementById('example_paginate') == null; } ); oTest.fnWaitTest( "Information div takes paging disabled into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Pagiantion enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bPaginate": true } ); }, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sUrl" ); /* Note that we only test the internal storage of language information pulled form a file here * as the other language tests will check it goes into the DOM correctly */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnTest( "sUrl is blank by default", null, function () { return oSettings.oLanguage.sUrl == ""; } ); oTest.fnWaitTest( "Loading of German file loads language information", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sUrl": "../../../examples/examples_support/de_DE.txt" } } ); oSettings = oTable.fnSettings(); }, function () { var bReturn = oSettings.oLanguage.sProcessing == "Bitte warten..." && oSettings.oLanguage.sLengthMenu == "_MENU_ Einträge anzeigen" && oSettings.oLanguage.sZeroRecords == "Keine Einträge vorhanden." && oSettings.oLanguage.sInfo == "_START_ bis _END_ von _TOTAL_ Einträgen" && oSettings.oLanguage.sInfoEmpty == "0 bis 0 von 0 Einträgen" && oSettings.oLanguage.sInfoFiltered == "(gefiltert von _MAX_ Einträgen)" && oSettings.oLanguage.sInfoPostFix == "" && oSettings.oLanguage.sSearch == "Suchen" && oSettings.oLanguage.oPaginate.sFirst == "Erster" && oSettings.oLanguage.oPaginate.sPrevious == "Zurück" && oSettings.oLanguage.oPaginate.sNext == "Nächster" && oSettings.oLanguage.oPaginate.sLast == "Letzter"; return bReturn; } ); /* One DOM check just to ensure that they go into the DOM */ oTest.fnTest( "Loaded language goes into the DOM", null, function () { return document.getElementById('example_info').innerHTML = "1 bis 10 von 57 Einträgen"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: js_data oTest.fnStart( "Sanity checks for DataTables with data from JS - Null data source for last column" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ null, null, null, null, { "mData": null } ], "aaData": gaaData }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Data in last column is empty", null, function () { return $('#example tbody td:eq(4)').html() == ""; } ); oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Data in last column is still empty", null, function () { return $('#example tbody td:eq(4)').html() == ""; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bSort" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Sorting is on by default", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnWaitTest( "Sorting Asc by default class applied", null, function () { return $('#example thead th:eq(0)').hasClass("sorting_asc"); } ); oTest.fnWaitTest( "Click on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Sorting class removed from first column", null, function () { return $('#example thead th:eq(0)').hasClass("sorting_asc") != true; } ); oTest.fnWaitTest( "Sorting asc class applied to second column", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_asc"); } ); oTest.fnWaitTest( "Reverse on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnWaitTest( "Sorting acs class removed from second column", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_asc") != true; } ); oTest.fnWaitTest( "Sorting desc class applied to second column", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_desc"); } ); /* Check can disable */ oTest.fnWaitTest( "Pagiantion can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bSort": false } ); }, function () { return $('#example tbody td:eq(3)').html() == "4"; } ); oTest.fnWaitTest( "Click on second column has no effect", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "4"; } ); oTest.fnWaitTest( "Reverse on second column has no effect", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "4"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Sorting enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bSort": true } ); }, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "sAjaxSource" ); /* Sanitfy check really - all the other tests blast this */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Server side is off by default", null, function () { return oSettings.sAjaxSource == "../../../examples/ajax/sources/objects.txt"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS - Object data source" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "aaData": [ { "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "4", "grade": "X" }, { "engine": "Trident", "browser": "Internet Explorer 5.0", "platform": "Win 95+", "version": "5", "grade": "C" }, { "engine": "Trident", "browser": "Internet Explorer 5.5", "platform": "Win 95+", "version": "5.5", "grade": "A" }, { "engine": "Trident", "browser": "Internet Explorer 6", "platform": "Win 98+", "version": "6", "grade": "A" }, { "engine": "Trident", "browser": "Internet Explorer 7", "platform": "Win XP SP2+", "version": "7", "grade": "A" }, { "engine": "Trident", "browser": "AOL browser (AOL desktop)", "platform": "Win XP", "version": "6", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 1.0", "platform": "Win 98+ / OSX.2+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 1.5", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 2.0", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 3.0", "platform": "Win 2k+ / OSX.3+", "version": "1.9", "grade": "A" }, { "engine": "Gecko", "browser": "Camino 1.0", "platform": "OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Camino 1.5", "platform": "OSX.3+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape 7.2", "platform": "Win 95+ / Mac OS 8.6-9.2", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape Browser 8", "platform": "Win 98SE+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape Navigator 9", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.0", "platform": "Win 95+ / OSX.1+", "version": "1", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.1", "platform": "Win 95+ / OSX.1+", "version": "1.1", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.2", "platform": "Win 95+ / OSX.1+", "version": "1.2", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.3", "platform": "Win 95+ / OSX.1+", "version": "1.3", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.4", "platform": "Win 95+ / OSX.1+", "version": "1.4", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.5", "platform": "Win 95+ / OSX.1+", "version": "1.5", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.6", "platform": "Win 95+ / OSX.1+", "version": "1.6", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.7", "platform": "Win 98+ / OSX.1+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.8", "platform": "Win 98+ / OSX.1+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Seamonkey 1.1", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Epiphany 2.20", "platform": "Gnome", "version": "1.8", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 1.2", "platform": "OSX.3", "version": "125.5", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 1.3", "platform": "OSX.3", "version": "312.8", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 2.0", "platform": "OSX.4+", "version": "419.3", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 3.0", "platform": "OSX.4+", "version": "522.1", "grade": "A" }, { "engine": "Webkit", "browser": "OmniWeb 5.5", "platform": "OSX.4+", "version": "420", "grade": "A" }, { "engine": "Webkit", "browser": "iPod Touch / iPhone", "platform": "iPod", "version": "420.1", "grade": "A" }, { "engine": "Webkit", "browser": "S60", "platform": "S60", "version": "413", "grade": "A" }, { "engine": "Presto", "browser": "Opera 7.0", "platform": "Win 95+ / OSX.1+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 7.5", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 8.0", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 8.5", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.0", "platform": "Win 95+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.2", "platform": "Win 88+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.5", "platform": "Win 88+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera for Wii", "platform": "Wii", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Nokia N800", "platform": "N800", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Nintendo DS browser", "platform": "Nintendo DS", "version": "8.5", "grade": "C/A<sup>1</sup>" }, { "engine": "KHTML", "browser": "Konqureror 3.1", "platform": "KDE 3.1", "version": "3.1", "grade": "C" }, { "engine": "KHTML", "browser": "Konqureror 3.3", "platform": "KDE 3.3", "version": "3.3", "grade": "A" }, { "engine": "KHTML", "browser": "Konqureror 3.5", "platform": "KDE 3.5", "version": "3.5", "grade": "A" }, { "engine": "Tasman", "browser": "Internet Explorer 4.5", "platform": "Mac OS 8-9", "version": "-", "grade": "X" }, { "engine": "Tasman", "browser": "Internet Explorer 5.1", "platform": "Mac OS 7.6-9", "version": "1", "grade": "C" }, { "engine": "Tasman", "browser": "Internet Explorer 5.2", "platform": "Mac OS 8-X", "version": "1", "grade": "C" }, { "engine": "Misc", "browser": "NetFront 3.1", "platform": "Embedded devices", "version": "-", "grade": "C" }, { "engine": "Misc", "browser": "NetFront 3.4", "platform": "Embedded devices", "version": "-", "grade": "A" }, { "engine": "Misc", "browser": "Dillo 0.8", "platform": "Embedded devices", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "Links", "platform": "Text only", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "Lynx", "platform": "Text only", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "IE Mobile", "platform": "Windows Mobile 6", "version": "-", "grade": "C" }, { "engine": "Misc", "browser": "PSP browser", "platform": "PSP", "version": "-", "grade": "C" }, { "engine": "Other browsers", "browser": "All others", "platform": "-", "version": "-", "grade": "U" } ] }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sProcessing" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "bProcessing": true } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Processing language is 'Processing...' by default", null, function () { return oSettings.oLanguage.sProcessing == "Processing..."; } ); oTest.fnTest( "Processing language default is in the DOM", null, function () { return document.getElementById('example_processing').innerHTML = "Processing..."; } ); oTest.fnWaitTest( "Processing language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bProcessing": true, "oLanguage": { "sProcessing": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sProcessing == "unit test"; } ); oTest.fnTest( "Processing language definition is in the DOM", null, function () { return document.getElementById('example_processing').innerHTML = "unit test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oSearch" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default values should be blank", null, function () { var bReturn = oSettings.oPreviousSearch.sSearch == "" && !oSettings.oPreviousSearch.bRegex; return bReturn; } ); /* This test might be considered iffy since the full object isn't given, but it's reasonable to * expect DataTables to cope with this. It should just assumine regex false */ oTest.fnWaitTest( "Search term only in object", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oSearch": { "sSearch": "Mozilla" } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnWaitTest( "New search will kill old one", function () { oTable.fnFilter("Opera"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Presto"; } ); oTest.fnWaitTest( "Search plain text term and escape regex true", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oSearch": { "sSearch": "DS", "bRegex": false } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Nintendo DS browser"; } ); oTest.fnWaitTest( "Search plain text term and escape regex false", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oSearch": { "sSearch": "Opera", "bRegex": true } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Presto"; } ); oTest.fnWaitTest( "Search regex text term and escape regex true", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oSearch": { "sSearch": "1.*", "bRegex": false } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnWaitTest( "Search regex text term and escape regex false", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oSearch": { "sSearch": "1.*", "bRegex": true } } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sZeroRecords" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Zero records language is 'No matching records found' by default", null, function () { return oSettings.oLanguage.sZeroRecords == "No matching records found"; } ); oTest.fnWaitTest( "Text is shown when empty table (after filtering)", function () { oTable.fnFilter('nothinghere'); }, function () { return $('#example tbody tr td')[0].innerHTML == "No matching records found" } ); oTest.fnWaitTest( "Zero records language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sZeroRecords": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sZeroRecords == "unit test"; } ); oTest.fnWaitTest( "Text is shown when empty table (after filtering)", function () { oTable.fnFilter('nothinghere2'); }, function () { return $('#example tbody tr td')[0].innerHTML == "unit test" } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.oPaginate" ); /* Note that the paging language information only has relevence in full numbers */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ], "sPaginationType": "full_numbers" } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "oLanguage.oPaginate defaults", null, function () { var bReturn = oSettings.oLanguage.oPaginate.sFirst == "First" && oSettings.oLanguage.oPaginate.sPrevious == "Previous" && oSettings.oLanguage.oPaginate.sNext == "Next" && oSettings.oLanguage.oPaginate.sLast == "Last"; return bReturn; } ); oTest.fnTest( "oLanguage.oPaginate defaults are in the DOM", null, function () { var bReturn = $('#example_paginate .first').html() == "First" && $('#example_paginate .previous').html() == "Previous" && $('#example_paginate .next').html() == "Next" && $('#example_paginate .last').html() == "Last"; return bReturn; } ); oTest.fnWaitTest( "oLanguage.oPaginate can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sPaginationType": "full_numbers", "oLanguage": { "oPaginate": { "sFirst": "unit1", "sPrevious": "test2", "sNext": "unit3", "sLast": "test4" } } } ); oSettings = oTable.fnSettings(); }, function () { var bReturn = oSettings.oLanguage.oPaginate.sFirst == "unit1" && oSettings.oLanguage.oPaginate.sPrevious == "test2" && oSettings.oLanguage.oPaginate.sNext == "unit3" && oSettings.oLanguage.oPaginate.sLast == "test4"; return bReturn; } ); oTest.fnTest( "oLanguage.oPaginate definitions are in the DOM", null, function () { var bReturn = $('#example_paginate .first').html() == "unit1" && $('#example_paginate .previous').html() == "test2" && $('#example_paginate .next').html() == "unit3" && $('#example_paginate .last').html() == "test4"; return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnDrawCallback" ); /* Fairly boring function compared to the others! */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); var mPass, bInit; oTest.fnWaitTest( "Default should be null", null, function () { return oSettings.fnDrawCallback == null; } ); oTest.fnWaitTest( "One argument passed", function () { oSession.fnRestore(); mPass = -1; bInit = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnDrawCallback": function ( ) { mPass = arguments.length; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return mPass == 1 && bInit; } ); oTest.fnWaitTest( "That one argument is the settings object", function () { oSession.fnRestore(); bInit = false; oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnDrawCallback": function ( oSettings ) { mPass = oSettings; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return oTable.fnSettings() == mPass && bInit; } ); /* The draw callback is called once for the init and then when the data is added */ oTest.fnWaitTest( "fnRowCallback called once on first draw", function () { oSession.fnRestore(); mPass = 0; bInit = false; $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnDrawCallback": function ( ) { mPass++; }, "fnInitComplete": function () { bInit = true; } } ); }, function () { return mPass == 2 && bInit; } ); oTest.fnWaitTest( "fnRowCallback called once on each draw there after as well", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return mPass == 5; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bAutoWidth" ); /* It's actually a little tricky to test this. We can't test absolute numbers because * different browsers and different platforms will render the width of the columns slightly * differently. However, we certainly can test the principle of what should happen (column * width doesn't change over pages) */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Auto width is enabled by default", null, function () { return oSettings.oFeatures.bAutoWidth; } ); oTest.fnWaitTest( "First column has a width assigned to it", null, function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); } ); /* This would seem like a better test - but there appear to be difficulties with tables which are bigger (calculated) than there is actually room for. I suspect this is actually a bug in datatables oTest.fnWaitTest( "Check column widths on first page match second page", null, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; $('#example_next').click(); var b0 = anThs[0].offsetWidth; var b1 = anThs[1].offsetWidth; var b2 = anThs[2].offsetWidth; var b3 = anThs[3].offsetWidth; var b4 = anThs[4].offsetWidth; console.log( a0, b0, a1, b1, a2, b2, a3, b3 ); if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) return true; else return false; } ); oTest.fnWaitTest( "Check column widths on second page match thid page", null, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; $('#example_next').click(); var b0 = anThs[0].offsetWidth; var b1 = anThs[1].offsetWidth; var b2 = anThs[2].offsetWidth; var b3 = anThs[3].offsetWidth; var b4 = anThs[4].offsetWidth; if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) return true; else return false; } ); */ /* Check can disable */ oTest.fnWaitTest( "Auto width can be disabled", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bAutoWidth": false } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bAutoWidth == false; } ); oTest.fnWaitTest( "First column does not have a width assigned to it", null, function () { return $('#example thead th:eq(0)').attr('style') == null; } ); /* oTest.fnWaitTest( "Check column widths on first page do not match second page", null, function () { var anThs = $('#example thead th'); var a0 = anThs[0].offsetWidth; var a1 = anThs[1].offsetWidth; var a2 = anThs[2].offsetWidth; var a3 = anThs[3].offsetWidth; var a4 = anThs[4].offsetWidth; $('#example_next').click(); var b0 = anThs[0].offsetWidth; var b1 = anThs[1].offsetWidth; var b2 = anThs[2].offsetWidth; var b3 = anThs[3].offsetWidth; var b4 = anThs[4].offsetWidth; if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) return false; else return true; } ); */ /* Enable makes no difference */ oTest.fnWaitTest( "Auto width enabled override", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bAutoWidth": true } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bAutoWidth; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bUseRendered" ); /* bUseRendered is used to alter sorting data, if false then the original data is used for * sorting rather than the rendered data */ $(document).ready( function () { /* Check the default */ var mTmp = 0; var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "fnRender": function (a) { if ( mTmp == 0 ) { mTmp++; return "aaa"; } else return a.aData['browser']; } }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default for bUseRendered is true - rendered data is used for sorting", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'aaa'; } ); oTest.fnWaitTest( "When bUseRendered is false, original data is used for sorting", function () { mTmp = 0; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "bUseRendered": false, "fnRender": function (a) { if ( mTmp == 0 ) { mTmp++; return "aaa"; } else { return a.aData['browser']; } } }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; } ); oTest.fnWaitTest( "bUseRendered set to false on one columns and true (default) on two others", function () { mTmp = 0; var mTmp2 = 0; var mTmp3 = 0; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine", "fnRender": function (a) { if ( mTmp == 0 ) { mTmp++; return "aaa1"; } else { return a.aData['engine']; } } }, { "mData": "browser", "bUseRendered": false, "fnRender": function (a) { if ( mTmp2 == 0 ) { mTmp2++; return "aaa2"; } else { return a.aData['browser']; } } }, { "mData": "platform", "fnRender": function (a) { if ( mTmp3 == 0 ) { mTmp3++; return "zzz3"; } else { return a.aData['platform']; } } }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'aaa1'; } ); oTest.fnWaitTest( "Multi-column rendering - 2nd column sorting", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; } ); oTest.fnWaitTest( "Multi-column rendering - 3rd column sorting", function () { $('#example thead th:eq(2)').click(); $('#example thead th:eq(2)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(2)').html() == 'zzz3'; } ); oTest.fnWaitTest( "Multi-column rendering - 4th column sorting", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == '-'; } ); oTest.fnWaitTest( "Multi-column rendering - 5th column sorting", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "fnServerData for Ajax sourced data" ); $(document).ready( function () { var mPass; oTest.fnTest( "Argument length", function () { $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnServerData": function () { mPass = arguments.length; } } ); }, function () { return mPass == 4; } ); oTest.fnTest( "Url", function () { $('#example').dataTable( { "bDestroy": true, "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnServerData": function (sUrl, aoData, fnCallback, oSettings) { mPass = sUrl == "../../../examples/ajax/sources/objects.txt"; } } ); }, function () { return mPass; } ); oTest.fnTest( "Data array", function () { $('#example').dataTable( { "bDestroy": true, "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnServerData": function (sUrl, aoData, fnCallback, oSettings) { mPass = aoData.length==0; } } ); }, function () { return mPass; } ); oTest.fnTest( "Callback function", function () { $('#example').dataTable( { "bDestroy": true, "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "fnServerData": function (sUrl, aoData, fnCallback, oSettings) { mPass = typeof fnCallback == 'function'; } } ); }, function () { return mPass; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bLengthChange" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Length div exists by default", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnWaitTest( "Four default options", null, function () { return $("select[name=example_length] option").length == 4; } ); oTest.fnWaitTest( "Default options", null, function () { var opts = $("select[name='example_length'] option"); return opts[0].getAttribute('value') == 10 && opts[1].getAttribute('value') == 25 && opts[2].getAttribute('value') == 50 && opts[3].getAttribute('value') == 100; } ); oTest.fnWaitTest( "Info takes length into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* Check can disable */ oTest.fnWaitTest( "Change length can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bLengthChange": false } ); }, function () { return document.getElementById('example_length') == null; } ); oTest.fnWaitTest( "Information takes length disabled into account", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Length change enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bLengthChange": true } ); }, function () { return document.getElementById('example_length') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bSortable" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "All columns are sortable by default", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "All others"; } ); oTest.fnWaitTest( "Can disable sorting from one column", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "bSortable": false }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() != "All others"; } ); oTest.fnWaitTest( "Disabled column has no sorting class", null, function () { return $('#example thead th:eq(1)').hasClass("sorting_asc") == false; } ); oTest.fnWaitTest( "Other columns can still sort", function () { $('#example thead th:eq(4)').click(); $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == "X"; } ); oTest.fnWaitTest( "Disable sorting on multiple columns - no sorting classes", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "bSortable": false }, { "mData": "platform" }, { "mData": "version", "bSortable": false }, { "mData": "grade" } ] } ); }, function () { var bReturn = $('#example thead th:eq(1)').hasClass("sorting") || $('#example thead th:eq(3)').hasClass("sorting") return bReturn == false; } ); oTest.fnWaitTest( "Sorting on disabled column 1 has no effect", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() != "All others"; } ); oTest.fnWaitTest( "Sorting on disabled column 2 has no effect", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() != "-"; } ); oTest.fnWaitTest( "Second sort on disabled column 2 has no effect", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() != "-"; } ); oTest.fnWaitTest( "Even with multiple disabled sorting columns other columns can still sort", function () { $('#example thead th:eq(4)').click(); $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == "X"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bInfo" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Info div exists by default", null, function () { return document.getElementById('example_info') != null; } ); /* Check can disable */ oTest.fnWaitTest( "Info can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bInfo": false } ); }, function () { return document.getElementById('example_info') == null; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Info enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bInfo": true } ); }, function () { return document.getElementById('example_info') != null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS - Object / sub-array data source" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "details.0" }, { "mData": "details.1" } ], "aaData": [ { "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "details": [ "4", "X" ] }, { "engine": "Trident", "browser": "Internet Explorer 5.0", "platform": "Win 95+", "details": [ "5", "C" ] }, { "engine": "Trident", "browser": "Internet Explorer 5.5", "platform": "Win 95+", "details": [ "5.5", "A" ] }, { "engine": "Trident", "browser": "Internet Explorer 6", "platform": "Win 98+", "details": [ "6", "A" ] }, { "engine": "Trident", "browser": "Internet Explorer 7", "platform": "Win XP SP2+", "details": [ "7", "A" ] }, { "engine": "Trident", "browser": "AOL browser (AOL desktop)", "platform": "Win XP", "details": [ "6", "A" ] }, { "engine": "Gecko", "browser": "Firefox 1.0", "platform": "Win 98+ / OSX.2+", "details": [ "1.7", "A" ] }, { "engine": "Gecko", "browser": "Firefox 1.5", "platform": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] }, { "engine": "Gecko", "browser": "Firefox 2.0", "platform": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] }, { "engine": "Gecko", "browser": "Firefox 3.0", "platform": "Win 2k+ / OSX.3+", "details": [ "1.9", "A" ] }, { "engine": "Gecko", "browser": "Camino 1.0", "platform": "OSX.2+", "details": [ "1.8", "A" ] }, { "engine": "Gecko", "browser": "Camino 1.5", "platform": "OSX.3+", "details": [ "1.8", "A" ] }, { "engine": "Gecko", "browser": "Netscape 7.2", "platform": "Win 95+ / Mac OS 8.6-9.2", "details": [ "1.7", "A" ] }, { "engine": "Gecko", "browser": "Netscape Browser 8", "platform": "Win 98SE+", "details": [ "1.7", "A" ] }, { "engine": "Gecko", "browser": "Netscape Navigator 9", "platform": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.0", "platform": "Win 95+ / OSX.1+", "details": [ 1, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.1", "platform": "Win 95+ / OSX.1+", "details": [ 1.1, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.2", "platform": "Win 95+ / OSX.1+", "details": [ 1.2, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.3", "platform": "Win 95+ / OSX.1+", "details": [ 1.3, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.4", "platform": "Win 95+ / OSX.1+", "details": [ 1.4, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.5", "platform": "Win 95+ / OSX.1+", "details": [ 1.5, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.6", "platform": "Win 95+ / OSX.1+", "details": [ 1.6, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.7", "platform": "Win 98+ / OSX.1+", "details": [ 1.7, "A" ] }, { "engine": "Gecko", "browser": "Mozilla 1.8", "platform": "Win 98+ / OSX.1+", "details": [ 1.8, "A" ] }, { "engine": "Gecko", "browser": "Seamonkey 1.1", "platform": "Win 98+ / OSX.2+", "details": [ "1.8", "A" ] }, { "engine": "Gecko", "browser": "Epiphany 2.20", "platform": "Gnome", "details": [ "1.8", "A" ] }, { "engine": "Webkit", "browser": "Safari 1.2", "platform": "OSX.3", "details": [ "125.5", "A" ] }, { "engine": "Webkit", "browser": "Safari 1.3", "platform": "OSX.3", "details": [ "312.8", "A" ] }, { "engine": "Webkit", "browser": "Safari 2.0", "platform": "OSX.4+", "details": [ "419.3", "A" ] }, { "engine": "Webkit", "browser": "Safari 3.0", "platform": "OSX.4+", "details": [ "522.1", "A" ] }, { "engine": "Webkit", "browser": "OmniWeb 5.5", "platform": "OSX.4+", "details": [ "420", "A" ] }, { "engine": "Webkit", "browser": "iPod Touch / iPhone", "platform": "iPod", "details": [ "420.1", "A" ] }, { "engine": "Webkit", "browser": "S60", "platform": "S60", "details": [ "413", "A" ] }, { "engine": "Presto", "browser": "Opera 7.0", "platform": "Win 95+ / OSX.1+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera 7.5", "platform": "Win 95+ / OSX.2+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera 8.0", "platform": "Win 95+ / OSX.2+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera 8.5", "platform": "Win 95+ / OSX.2+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera 9.0", "platform": "Win 95+ / OSX.3+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera 9.2", "platform": "Win 88+ / OSX.3+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera 9.5", "platform": "Win 88+ / OSX.3+", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Opera for Wii", "platform": "Wii", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Nokia N800", "platform": "N800", "details": [ "-", "A" ] }, { "engine": "Presto", "browser": "Nintendo DS browser", "platform": "Nintendo DS", "details": [ "8.5", "C/A<sup>1</sup>" ] }, { "engine": "KHTML", "browser": "Konqureror 3.1", "platform": "KDE 3.1", "details": [ "3.1", "C" ] }, { "engine": "KHTML", "browser": "Konqureror 3.3", "platform": "KDE 3.3", "details": [ "3.3", "A" ] }, { "engine": "KHTML", "browser": "Konqureror 3.5", "platform": "KDE 3.5", "details": [ "3.5", "A" ] }, { "engine": "Tasman", "browser": "Internet Explorer 4.5", "platform": "Mac OS 8-9", "details": [ "-", "X" ] }, { "engine": "Tasman", "browser": "Internet Explorer 5.1", "platform": "Mac OS 7.6-9", "details": [ "1", "C" ] }, { "engine": "Tasman", "browser": "Internet Explorer 5.2", "platform": "Mac OS 8-X", "details": [ "1", "C" ] }, { "engine": "Misc", "browser": "NetFront 3.1", "platform": "Embedded devices", "details": [ "-", "C" ] }, { "engine": "Misc", "browser": "NetFront 3.4", "platform": "Embedded devices", "details": [ "-", "A" ] }, { "engine": "Misc", "browser": "Dillo 0.8", "platform": "Embedded devices", "details": [ "-", "X" ] }, { "engine": "Misc", "browser": "Links", "platform": "Text only", "details": [ "-", "X" ] }, { "engine": "Misc", "browser": "Lynx", "platform": "Text only", "details": [ "-", "X" ] }, { "engine": "Misc", "browser": "IE Mobile", "platform": "Windows Mobile 6", "details": [ "-", "C" ] }, { "engine": "Misc", "browser": "PSP browser", "platform": "PSP", "details": [ "-", "C" ] }, { "engine": "Other browsers", "browser": "All others", "platform": "-", "details": [ "-", "U" ] } ] }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bSortClasses" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Sorting classes are applied by default", null, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'); } ); oTest.fnWaitTest( "Sorting classes are applied to all required cells", null, function () { return $('#example tbody tr:eq(7) td:eq(0)').hasClass('sorting_1'); } ); oTest.fnWaitTest( "Sorting classes are not applied to non-sorting columns", null, function () { return $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_1') == false; } ); oTest.fnWaitTest( "Sorting multi-column - add column 1", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2'); } ); oTest.fnWaitTest( "Sorting multi-column - add column 2", function () { oDispacher.click( $('#example thead th:eq(2)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3'); } ); oTest.fnWaitTest( "Sorting multi-column - add column 3", function () { oDispacher.click( $('#example thead th:eq(3)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') && $('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3'); } ); oTest.fnWaitTest( "Remove sorting classes on single column sort", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') == false && $('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3') == false; } ); oTest.fnWaitTest( "Sorting class 1 was added", null, function () { return $('#example tbody tr:eq(1) td:eq(4)').hasClass('sorting_1'); } ); /* Check can disable */ oTest.fnWaitTest( "Sorting classes can be disabled", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bSortClasses": false } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false; } ); oTest.fnWaitTest( "Sorting classes disabled - add column 1 - no effect", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false; } ); oTest.fnWaitTest( "Sorting classes disabled - add column 2 - no effect", function () { oDispacher.click( $('#example thead th:eq(2)')[0], { 'shift': true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1') == false && $('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2') == false && $('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3') == false; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Sorting classes enabled override", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bSortClasses": true } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'); } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.iDataSort" ); $(document).ready( function () { /* Should know that sorting already works by default from other tests, so we can jump * right in here */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "iDataSort": 4 }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Sorting on first column is uneffected", null, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko'; } ); oTest.fnWaitTest( "Sorting on second column is the order of the fifth", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnWaitTest( "Reserve sorting on second column uses fifth column as well", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'X'; } ); oTest.fnWaitTest( "Sorting on 5th column retains it's own sorting", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnWaitTest( "Use 2nd col for sorting 5th col and via-versa - no effect on first col sorting", function () { mTmp = 0; oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "iDataSort": 4 }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade", "iDataSort": 1 } ] } ); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 'Gecko'; } ); oTest.fnWaitTest( "2nd col sorting uses fifth col", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'A'; } ); oTest.fnWaitTest( "2nd col sorting uses fifth col - reversed", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(4)').html() == 'X'; } ); oTest.fnWaitTest( "5th col sorting uses 2nd col", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'All others'; } ); oTest.fnWaitTest( "5th col sorting uses 2nd col - reversed", function () { $('#example thead th:eq(4)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == 'Seamonkey 1.1'; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bSeachable" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Columns are searchable by default", function () { oTable.fnFilter("Camino"); }, function () { if ( $('#example tbody tr:eq(0) td:eq(1)')[0] ) return $('#example tbody tr:eq(0) td:eq(1)').html().match(/Camino/); else return null; } ); oTest.fnWaitTest( "Disabling sorting on a column removes it from the global filter", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "bSearchable": false }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oSettings = oTable.fnSettings(); oTable.fnFilter("Camino"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnWaitTest( "Disabled on one column has no effect on other columns", function () { oTable.fnFilter("Webkit"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Webkit"; } ); oTest.fnWaitTest( "Disable filtering on multiple columns", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine", "bSearchable": false }, { "mData": "browser", "bSearchable": false }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oSettings = oTable.fnSettings(); oTable.fnFilter("Webkit"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnWaitTest( "Filter on second disabled column", function () { oTable.fnFilter("Camino"); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS - Array / sub-object data source" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ null, null, { "mData": 2 }, { "mData": "3.version" }, { "mData": "3.grade" } ], "aaData": [ [ "Trident", "Internet Explorer 4.0", "Win 95+", { "version": "4", "grade": "X" } ], [ "Trident", "Internet Explorer 5.0", "Win 95+", { "version": "5", "grade": "C" } ], [ "Trident", "Internet Explorer 5.5", "Win 95+", { "version": "5.5", "grade": "A" } ], [ "Trident", "Internet Explorer 6", "Win 98+", { "version": "6", "grade": "A" } ], [ "Trident", "Internet Explorer 7", "Win XP SP2+", { "version": "7", "grade": "A" } ], [ "Trident", "AOL browser (AOL desktop)", "Win XP", { "version": "6", "grade": "A" } ], [ "Gecko", "Firefox 1.0", "Win 98+ / OSX.2+", { "version": "1.7", "grade": "A" } ], [ "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Firefox 2.0", "Win 98+ / OSX.2+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Firefox 3.0", "Win 2k+ / OSX.3+", { "version": "1.9", "grade": "A" } ], [ "Gecko", "Camino 1.0", "OSX.2+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Camino 1.5", "OSX.3+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Netscape 7.2", "Win 95+ / Mac OS 8.6-9.2", { "version": "1.7", "grade": "A" } ], [ "Gecko", "Netscape Browser 8", "Win 98SE+", { "version": "1.7", "grade": "A" } ], [ "Gecko", "Netscape Navigator 9", "Win 98+ / OSX.2+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Mozilla 1.0", "Win 95+ / OSX.1+", { "version": "1", "grade": "A" } ], [ "Gecko", "Mozilla 1.1", "Win 95+ / OSX.1+", { "version": "1.1", "grade": "A" } ], [ "Gecko", "Mozilla 1.2", "Win 95+ / OSX.1+", { "version": "1.2", "grade": "A" } ], [ "Gecko", "Mozilla 1.3", "Win 95+ / OSX.1+", { "version": "1.3", "grade": "A" } ], [ "Gecko", "Mozilla 1.4", "Win 95+ / OSX.1+", { "version": "1.4", "grade": "A" } ], [ "Gecko", "Mozilla 1.5", "Win 95+ / OSX.1+", { "version": "1.5", "grade": "A" } ], [ "Gecko", "Mozilla 1.6", "Win 95+ / OSX.1+", { "version": "1.6", "grade": "A" } ], [ "Gecko", "Mozilla 1.7", "Win 98+ / OSX.1+", { "version": "1.7", "grade": "A" } ], [ "Gecko", "Mozilla 1.8", "Win 98+ / OSX.1+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Seamonkey 1.1", "Win 98+ / OSX.2+", { "version": "1.8", "grade": "A" } ], [ "Gecko", "Epiphany 2.20", "Gnome", { "version": "1.8", "grade": "A" } ], [ "Webkit", "Safari 1.2", "OSX.3", { "version": "125.5", "grade": "A" } ], [ "Webkit", "Safari 1.3", "OSX.3", { "version": "312.8", "grade": "A" } ], [ "Webkit", "Safari 2.0", "OSX.4+", { "version": "419.3", "grade": "A" } ], [ "Webkit", "Safari 3.0", "OSX.4+", { "version": "522.1", "grade": "A" } ], [ "Webkit", "OmniWeb 5.5", "OSX.4+", { "version": "420", "grade": "A" } ], [ "Webkit", "iPod Touch / iPhone", "iPod", { "version": "420.1", "grade": "A" } ], [ "Webkit", "S60", "S60", { "version": "413", "grade": "A" } ], [ "Presto", "Opera 7.0", "Win 95+ / OSX.1+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera 7.5", "Win 95+ / OSX.2+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera 8.0", "Win 95+ / OSX.2+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera 8.5", "Win 95+ / OSX.2+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera 9.0", "Win 95+ / OSX.3+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera 9.2", "Win 88+ / OSX.3+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera 9.5", "Win 88+ / OSX.3+", { "version": "-", "grade": "A" } ], [ "Presto", "Opera for Wii", "Wii", { "version": "-", "grade": "A" } ], [ "Presto", "Nokia N800", "N800", { "version": "-", "grade": "A" } ], [ "Presto", "Nintendo DS browser", "Nintendo DS", { "version": "8.5", "grade": "C/A<sup>1</sup>" } ], [ "KHTML", "Konqureror 3.1", "KDE 3.1", { "version": "3.1", "grade": "C" } ], [ "KHTML", "Konqureror 3.3", "KDE 3.3", { "version": "3.3", "grade": "A" } ], [ "KHTML", "Konqureror 3.5", "KDE 3.5", { "version": "3.5", "grade": "A" } ], [ "Tasman", "Internet Explorer 4.5", "Mac OS 8-9", { "version": "-", "grade": "X" } ], [ "Tasman", "Internet Explorer 5.1", "Mac OS 7.6-9", { "version": "1", "grade": "C" } ], [ "Tasman", "Internet Explorer 5.2", "Mac OS 8-X", { "version": "1", "grade": "C" } ], [ "Misc", "NetFront 3.1", "Embedded devices", { "version": "-", "grade": "C" } ], [ "Misc", "NetFront 3.4", "Embedded devices", { "version": "-", "grade": "A" } ], [ "Misc", "Dillo 0.8", "Embedded devices", { "version": "-", "grade": "X" } ], [ "Misc", "Links", "Text only", { "version": "-", "grade": "X" } ], [ "Misc", "Lynx", "Text only", { "version": "-", "grade": "X" } ], [ "Misc", "IE Mobile", "Windows Mobile 6", { "version": "-", "grade": "C" } ], [ "Misc", "PSP browser", "PSP", { "version": "-", "grade": "C" } ], [ "Other browsers", "All others", "-", { "version": "-", "grade": "U" } ] ] }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "aoColumns.bVisible" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "All columns are visible by default", null, function () { return $('#example tbody tr:eq(0) td').length == 5; } ); oTest.fnWaitTest( "Can hide one column and it removes td column from DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "bVisible": false }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); }, function () { return $('#example tbody tr:eq(0) td').length == 4; } ); oTest.fnWaitTest( "Can hide one column and it removes thead th column from DOM", null, function () { return $('#example thead tr:eq(0) th').length == 4; } ); oTest.fnWaitTest( "The correct thead column has been hidden", null, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "Platform(s)" && jqNodes[2].innerHTML == "Engine version" && jqNodes[3].innerHTML == "CSS grade"; return bReturn; } ); oTest.fnWaitTest( "The correct tbody column has been hidden", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var jqNodes = $('#example tbody tr:eq(0) td'); var bReturn = jqNodes[0].innerHTML == "Gecko" && jqNodes[1].innerHTML == "Gnome" && jqNodes[2].innerHTML == "1.8" && jqNodes[3].innerHTML == "A"; return bReturn; } ); oTest.fnWaitTest( "Can hide multiple columns and it removes td column from DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser", "bVisible": false }, { "mData": "platform", "bVisible": false }, { "mData": "version" }, { "mData": "grade", "bVisible": false } ] } ); }, function () { return $('#example tbody tr:eq(0) td').length == 2; } ); oTest.fnWaitTest( "Multiple hide - removes thead th column from DOM", null, function () { return $('#example thead tr:eq(0) th').length == 2; } ); oTest.fnWaitTest( "Multiple hide - the correct thead columns have been hidden", null, function () { var jqNodes = $('#example thead tr:eq(0) th'); var bReturn = jqNodes[0].innerHTML == "Rendering engine" && jqNodes[1].innerHTML == "Engine version" return bReturn; } ); oTest.fnWaitTest( "Multiple hide - the correct tbody columns have been hidden", function () { oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var jqNodes = $('#example tbody tr:eq(0) td'); var bReturn = jqNodes[0].innerHTML == "Gecko" && jqNodes[1].innerHTML == "1" return bReturn; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "Sanity checks for DataTables with data from JS - Object data source" ); oTest.fnTest( "jQuery.dataTable function", null, function () { return typeof jQuery().dataTable == "function"; } ); oTest.fnTest( "jQuery.dataTableSettings storage array", null, function () { return typeof jQuery().dataTableSettings == "object"; } ); oTest.fnTest( "jQuery.dataTableExt plugin object", null, function () { return typeof jQuery().dataTableExt == "object"; } ); $(document).ready( function () { var oInit = { "aoColumns": [ { "mDataProp": "engine" }, { "mDataProp": "browser" }, { "mDataProp": "platform" }, { "mDataProp": "version" }, { "mDataProp": "grade" } ], "aaData": [ { "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "4", "grade": "X" }, { "engine": "Trident", "browser": "Internet Explorer 5.0", "platform": "Win 95+", "version": "5", "grade": "C" }, { "engine": "Trident", "browser": "Internet Explorer 5.5", "platform": "Win 95+", "version": "5.5", "grade": "A" }, { "engine": "Trident", "browser": "Internet Explorer 6", "platform": "Win 98+", "version": "6", "grade": "A" }, { "engine": "Trident", "browser": "Internet Explorer 7", "platform": "Win XP SP2+", "version": "7", "grade": "A" }, { "engine": "Trident", "browser": "AOL browser (AOL desktop)", "platform": "Win XP", "version": "6", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 1.0", "platform": "Win 98+ / OSX.2+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 1.5", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 2.0", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Firefox 3.0", "platform": "Win 2k+ / OSX.3+", "version": "1.9", "grade": "A" }, { "engine": "Gecko", "browser": "Camino 1.0", "platform": "OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Camino 1.5", "platform": "OSX.3+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape 7.2", "platform": "Win 95+ / Mac OS 8.6-9.2", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape Browser 8", "platform": "Win 98SE+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Netscape Navigator 9", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.0", "platform": "Win 95+ / OSX.1+", "version": "1", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.1", "platform": "Win 95+ / OSX.1+", "version": "1.1", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.2", "platform": "Win 95+ / OSX.1+", "version": "1.2", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.3", "platform": "Win 95+ / OSX.1+", "version": "1.3", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.4", "platform": "Win 95+ / OSX.1+", "version": "1.4", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.5", "platform": "Win 95+ / OSX.1+", "version": "1.5", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.6", "platform": "Win 95+ / OSX.1+", "version": "1.6", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.7", "platform": "Win 98+ / OSX.1+", "version": "1.7", "grade": "A" }, { "engine": "Gecko", "browser": "Mozilla 1.8", "platform": "Win 98+ / OSX.1+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Seamonkey 1.1", "platform": "Win 98+ / OSX.2+", "version": "1.8", "grade": "A" }, { "engine": "Gecko", "browser": "Epiphany 2.20", "platform": "Gnome", "version": "1.8", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 1.2", "platform": "OSX.3", "version": "125.5", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 1.3", "platform": "OSX.3", "version": "312.8", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 2.0", "platform": "OSX.4+", "version": "419.3", "grade": "A" }, { "engine": "Webkit", "browser": "Safari 3.0", "platform": "OSX.4+", "version": "522.1", "grade": "A" }, { "engine": "Webkit", "browser": "OmniWeb 5.5", "platform": "OSX.4+", "version": "420", "grade": "A" }, { "engine": "Webkit", "browser": "iPod Touch / iPhone", "platform": "iPod", "version": "420.1", "grade": "A" }, { "engine": "Webkit", "browser": "S60", "platform": "S60", "version": "413", "grade": "A" }, { "engine": "Presto", "browser": "Opera 7.0", "platform": "Win 95+ / OSX.1+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 7.5", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 8.0", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 8.5", "platform": "Win 95+ / OSX.2+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.0", "platform": "Win 95+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.2", "platform": "Win 88+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera 9.5", "platform": "Win 88+ / OSX.3+", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Opera for Wii", "platform": "Wii", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Nokia N800", "platform": "N800", "version": "-", "grade": "A" }, { "engine": "Presto", "browser": "Nintendo DS browser", "platform": "Nintendo DS", "version": "8.5", "grade": "C/A<sup>1</sup>" }, { "engine": "KHTML", "browser": "Konqureror 3.1", "platform": "KDE 3.1", "version": "3.1", "grade": "C" }, { "engine": "KHTML", "browser": "Konqureror 3.3", "platform": "KDE 3.3", "version": "3.3", "grade": "A" }, { "engine": "KHTML", "browser": "Konqureror 3.5", "platform": "KDE 3.5", "version": "3.5", "grade": "A" }, { "engine": "Tasman", "browser": "Internet Explorer 4.5", "platform": "Mac OS 8-9", "version": "-", "grade": "X" }, { "engine": "Tasman", "browser": "Internet Explorer 5.1", "platform": "Mac OS 7.6-9", "version": "1", "grade": "C" }, { "engine": "Tasman", "browser": "Internet Explorer 5.2", "platform": "Mac OS 8-X", "version": "1", "grade": "C" }, { "engine": "Misc", "browser": "NetFront 3.1", "platform": "Embedded devices", "version": "-", "grade": "C" }, { "engine": "Misc", "browser": "NetFront 3.4", "platform": "Embedded devices", "version": "-", "grade": "A" }, { "engine": "Misc", "browser": "Dillo 0.8", "platform": "Embedded devices", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "Links", "platform": "Text only", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "Lynx", "platform": "Text only", "version": "-", "grade": "X" }, { "engine": "Misc", "browser": "IE Mobile", "platform": "Windows Mobile 6", "version": "-", "grade": "C" }, { "engine": "Misc", "browser": "PSP browser", "platform": "PSP", "version": "-", "grade": "C" }, { "engine": "Other browsers", "browser": "All others", "platform": "-", "version": "-", "grade": "U" } ] }; $('#example').dataTable( oInit ); /* Basic checks */ oTest.fnWaitTest( "Length changing div exists", null, function () { return document.getElementById('example_length') != null; } ); oTest.fnTest( "Filtering div exists", null, function () { return document.getElementById('example_filter') != null; } ); oTest.fnTest( "Information div exists", null, function () { return document.getElementById('example_info') != null; } ); oTest.fnTest( "Pagination div exists", null, function () { return document.getElementById('example_paginate') != null; } ); oTest.fnTest( "Processing div is off by default", null, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "10 rows shown on the first page", null, function () { return $('#example tbody tr').length == 10; } ); oTest.fnTest( "Initial sort occured", null, function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } ); /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ oTest.fnTest( "Sorting (first click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (second click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Sorting (third click) on second column", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Sorting (first click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "-"; } ); oTest.fnTest( "Sorting (second click) on numeric column", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody td:eq(3)').html() == "522.1"; } ); oTest.fnTest( "Sorting multi-column (first click)", function () { $('#example thead th:eq(0)').click(); oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, function () { var b = $('#example tbody td:eq(0)').html() == "Gecko" && $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } ); oTest.fnTest( "Sorting multi-column - sorting second column only", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Basic paging */ oTest.fnTest( "Paging to second page", function () { $('#example_next').click(); }, function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; } ); oTest.fnTest( "Paging to first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); oTest.fnTest( "Attempting to page back beyond the first page", function () { $('#example_previous').click(); }, function () { return $('#example tbody td:eq(1)').html() == "All others"; } ); /* Changing length */ oTest.fnTest( "Changing table length to 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return $('#example tbody tr').length == 25; } ); oTest.fnTest( "Changing table length to 50 records", function () { $("select[name=example_length]").val('50').change(); }, function () { return $('#example tbody tr').length == 50; } ); oTest.fnTest( "Changing table length to 100 records", function () { $("select[name=example_length]").val('100').change(); }, function () { return $('#example tbody tr').length == 57; } ); oTest.fnTest( "Changing table length to 10 records", function () { $("select[name=example_length]").val('10').change(); }, function () { return $('#example tbody tr').length == 10; } ); /* * Information element */ oTest.fnTest( "Information on zero config", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information on second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } ); oTest.fnTest( "Information on third page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } ); oTest.fnTest( "Information on last page", function () { $('#example_next').click(); $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } ); oTest.fnTest( "Information back on first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with 25 records", function () { $("select[name=example_length]").val('25').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } ); oTest.fnTest( "Information with 25 records - second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } ); oTest.fnTest( "Information with 100 records - first page", function () { $('#example_previous').click(); $("select[name=example_length]").val('100').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } ); oTest.fnTest( "Information back to 10 records", function () { $('#example_previous').click(); $("select[name=example_length]").val('10').change(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Information with filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' last page", function () { $('#example_next').click(); $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' back to first page", function () { $('#example_previous').click(); $('#example_previous').click(); $('#example_previous').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - second time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter increased to 'Win 98'", function () { $('#example_filter input').val("Win 98").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter decreased to 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter 'Win' second page - third time", function () { $('#example_next').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Information with filter removed", function () { $('#example_filter input').val("").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); /* * Filtering */ oTest.fnWaitTest( "Filter 'W' - rows", function () { /* Reset the table such that the old sorting doesn't mess things up */ oSession.fnRestore(); $('#example').dataTable( oInit ); $('#example_filter input').val("W").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; } ); oTest.fnTest( "Filter 'W' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Wi'", function () { $('#example_filter input').val("Wi").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win'", function () { $('#example_filter input').val("Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'Win' - sorting column 1 reverse", function () { $('#example thead th:eq(1)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } ); oTest.fnTest( "Filter 'Win XP' - maintaing reverse sorting col 1", function () { $('#example_filter input').val("Win XP").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; } ); oTest.fnTest( "Filter 'Win XP' - sorting col 3 - reversed", function () { $('#example thead th:eq(3)').click(); }, function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } ); oTest.fnTest( "Filter 'Win' - sorting col 3 - reversed info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter 'nothinghere'", function () { $('#example_filter input').val("nothinghere").keyup(); }, function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found"; } ); oTest.fnTest( "Filter 'nothinghere' - info", null, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Filter back to blank and 1st column sorting", function () { $('#example_filter input').val("").keyup(); $('#example thead th:eq(0)').click(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } ); oTest.fnTest( "Prefixing a filter entry", function () { $('#example_filter input').val("Win").keyup(); $('#example_filter input').val("GeckoWin").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } ); oTest.fnTest( "Prefixing a filter entry with space", function () { $('#example_filter input').val("Gecko Win").keyup(); }, function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bProcessing" ); /* It's actually a bit hard to set this one due to the fact that it will only be shown * when DataTables is doing some kind of processing. The server-side processing is a bit * better to test this than here - so we just the interal functions to enable it and check * that it is available */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Processing is off by default", null, function () { return oSettings.oFeatures.bProcessing == false; } ); oTest.fnWaitTest( "Processing div is not in the DOM", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "Processing div cannot be shown", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing') == null; } ); oTest.fnWaitTest( "Processing div cannot be hidden", function () { oTable.oApi._fnProcessingDisplay( oSettings, false ); }, function () { return document.getElementById('example_processing') == null; } ); /* Check can disable */ oTest.fnWaitTest( "Processing can be enabled", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bProcessing": true } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bProcessing == true; } ); oTest.fnWaitTest( "Processing div is in the DOM", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing'); } ); oTest.fnWaitTest( "Processing div is hidden by default", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing').style.visibility = "hidden"; } ); oTest.fnWaitTest( "Processing div can be shown", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing').style.visibility = "visible"; } ); oTest.fnWaitTest( "Processing div can be hidden", function () { oTable.oApi._fnProcessingDisplay( oSettings, false ); }, function () { return document.getElementById('example_processing').style.visibility = "hidden"; } ); /* Enable makes no difference */ oTest.fnWaitTest( "Processing disabled override", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "bProcessing": false } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oFeatures.bProcessing == false; } ); oTest.fnWaitTest( "Processing div is not in the DOM", function () { oTable.oApi._fnProcessingDisplay( oSettings, true ); }, function () { return document.getElementById('example_processing') == null; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "oLanguage.sInfoPostFix" ); $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Info post fix language is '' (blank) by default", null, function () { return oSettings.oLanguage.sInfoPostFix == ""; } ); oTest.fnTest( "Width no post fix, the basic info shows", null, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries"; } ); oTest.fnWaitTest( "Info post fix language can be defined", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sInfoPostFix": "unit test" } } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.oLanguage.sInfoPostFix == "unit test"; } ); oTest.fnTest( "Info empty language default is in the DOM", null, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries unit test"; } ); oTest.fnWaitTest( "Macros have no effect in the post fix", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sInfoPostFix": "unit _START_ _END_ _TOTAL_ test" } } ); }, function () { return document.getElementById('example_info').innerHTML = "Showing 1 to 10 of 57 entries unit _START_ _END_ _TOTAL_ test"; } ); oTest.fnWaitTest( "Post fix is applied after fintering info", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "oLanguage": { "sInfoPostFix": "unit test" } } ); oTable.fnFilter("nothinghere"); }, function () { return document.getElementById('example_info').innerHTML = "Showing 0 to 0 of 0 entries unit (filtered from 57 total entries) test"; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "asStripeClasses" ); $(document).ready( function () { /* Check the default */ $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); oTest.fnWaitTest( "Default row striping is applied", null, function () { return $('#example tbody tr:eq(0)').hasClass('odd') && $('#example tbody tr:eq(1)').hasClass('even') && $('#example tbody tr:eq(2)').hasClass('odd') && $('#example tbody tr:eq(3)').hasClass('even'); } ); oTest.fnWaitTest( "Row striping on the second page", function () { $('#example_next').click(); }, function () { return $('#example tbody tr:eq(0)').hasClass('odd') && $('#example tbody tr:eq(1)').hasClass('even') && $('#example tbody tr:eq(2)').hasClass('odd') && $('#example tbody tr:eq(3)').hasClass('even'); } ); /* No striping */ oTest.fnWaitTest( "No row striping", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "asStripeClasses": [] } ); }, function () { if ( typeof $('#example tbody tr:eq(1)')[0] == 'undefined' ) { /* Use the 'wait for' to allow this to become true */ return false; } return $('#example tbody tr:eq(0)')[0].className == "" && $('#example tbody tr:eq(1)')[0].className == "" && $('#example tbody tr:eq(2)')[0].className == "" && $('#example tbody tr:eq(3)')[0].className == ""; } ); /* Custom striping */ oTest.fnWaitTest( "Custom striping [2]", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "asStripeClasses": [ 'test1', 'test2' ] } ); }, function () { return $('#example tbody tr:eq(0)').hasClass('test1') && $('#example tbody tr:eq(1)').hasClass('test2') && $('#example tbody tr:eq(2)').hasClass('test1') && $('#example tbody tr:eq(3)').hasClass('test2'); } ); /* long array of striping */ oTest.fnWaitTest( "Custom striping [4]", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "asStripeClasses": [ 'test1', 'test2', 'test3', 'test4' ] } ); }, function () { return $('#example tbody tr:eq(0)').hasClass('test1') && $('#example tbody tr:eq(1)').hasClass('test2') && $('#example tbody tr:eq(2)').hasClass('test3') && $('#example tbody tr:eq(3)').hasClass('test4'); } ); oTest.fnWaitTest( "Custom striping is restarted on second page [2]", function () { $('#example_next').click(); }, function () { return $('#example tbody tr:eq(0)').hasClass('test1') && $('#example tbody tr:eq(1)').hasClass('test2') && $('#example tbody tr:eq(2)').hasClass('test3') && $('#example tbody tr:eq(3)').hasClass('test4'); } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "bServerSide" ); /* Not interested in server-side processing here other than to check that it is off */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Server side is off by default", null, function () { return oSettings.oFeatures.bServerSide == false; } ); oTest.fnComplete(); } );
JavaScript
// DATA_TEMPLATE: empty_table oTest.fnStart( "sDom" ); /* This is going to be brutal on the browser! There is a lot that can be tested here... */ $(document).ready( function () { /* Check the default */ var oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumns": [ { "mData": "engine" }, { "mData": "browser" }, { "mData": "platform" }, { "mData": "version" }, { "mData": "grade" } ] } ); var oSettings = oTable.fnSettings(); oTest.fnWaitTest( "Default DOM varaible", null, function () { return oSettings.sDom == "lfrtip"; } ); oTest.fnWaitTest( "Default DOM in document", null, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && nNodes[2] == nFilter && nNodes[3] == nTable && nNodes[4] == nInfo && nNodes[5] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check example 1 in code propagates", function () { oSession.fnRestore(); oTable = $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sDom": '<"wrapper"flipt>' } ); oSettings = oTable.fnSettings(); }, function () { return oSettings.sDom == '<"wrapper"flipt>'; } ); oTest.fnWaitTest( "Check example 1 in DOM", null, function () { var jqNodes = $('#demo div, #demo table'); var nNodes = []; /* Strip the paging nodes */ for ( var i=0, iLen=jqNodes.length ; i<iLen ; i++ ) { if ( jqNodes[i].getAttribute('id') != "example_previous" && jqNodes[i].getAttribute('id') != "example_next" ) { nNodes.push( jqNodes[i] ); } } var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var nCustomWrapper = $('div.wrapper')[0]; var bReturn = nNodes[0] == nWrapper && nNodes[1] == nCustomWrapper && nNodes[2] == nFilter && nNodes[3] == nLength && nNodes[4] == nInfo && nNodes[5] == nPaging && nNodes[6] == nTable; return bReturn; } ); oTest.fnWaitTest( "Check example 2 in DOM", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sDom": '<lf<t>ip>' } ); }, function () { var jqNodes = $('#demo div, #demo table'); var nNodes = []; var nCustomWrappers = [] /* Strip the paging nodes */ for ( var i=0, iLen=jqNodes.length ; i<iLen ; i++ ) { if ( jqNodes[i].getAttribute('id') != "example_previous" && jqNodes[i].getAttribute('id') != "example_next" ) { nNodes.push( jqNodes[i] ); } /* Only the two custom divs don't have class names */ if ( jqNodes[i].className == "" ) { nCustomWrappers.push( jqNodes[i] ); } } var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nCustomWrappers[0] && nNodes[2] == nLength && nNodes[3] == nFilter && nNodes[4] == nCustomWrappers[1] && nNodes[5] == nTable && nNodes[6] == nInfo && nNodes[7] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check no length element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sDom": 'frtip' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && null == nLength && nNodes[1] == nFilter && nNodes[2] == nTable && nNodes[3] == nInfo && nNodes[4] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check no filter element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sDom": 'lrtip' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && null == nFilter && nNodes[2] == nTable && nNodes[3] == nInfo && nNodes[4] == nPaging; return bReturn; } ); /* Note we don't test for no table as this is not supported (and it would be fairly daft! */ oTest.fnWaitTest( "Check no info element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sDom": 'lfrtp' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && nNodes[2] == nFilter && nNodes[3] == nTable && null == nInfo && nNodes[4] == nPaging; return bReturn; } ); oTest.fnWaitTest( "Check no paging element", function () { oSession.fnRestore(); $('#example').dataTable( { "sAjaxSource": "../../../examples/ajax/sources/objects.txt", "aoColumnDefs": [ { "mData": "engine", "aTargets": [0] }, { "mData": "browser", "aTargets": [1] }, { "mData": "platform", "aTargets": [2] }, { "mData": "version", "aTargets": [3] }, { "mData": "grade", "aTargets": [4] } ], "sDom": 'lfrti' } ); }, function () { var nNodes = $('#demo div, #demo table'); var nWrapper = document.getElementById('example_wrapper'); var nLength = document.getElementById('example_length'); var nFilter = document.getElementById('example_filter'); var nInfo = document.getElementById('example_info'); var nPaging = document.getElementById('example_paginate'); var nTable = document.getElementById('example'); var bReturn = nNodes[0] == nWrapper && nNodes[1] == nLength && nNodes[2] == nFilter && nNodes[3] == nTable && nNodes[4] == nInfo && null == nPaging; return bReturn; } ); oTest.fnComplete(); } );
JavaScript