/** * Copyright (c)2005-2009 Matt Kruse (javascripttoolbox.com) * * Dual licensed under the MIT and GPL licenses. * This basically means you can use this code however you want for * free, but don't claim to have written it yourself! * Donations always accepted: http://www.JavascriptToolbox.com/donate/ * * Please do not link to the .js files on javascripttoolbox.com from * your site. Copy the files locally to your server instead. * */ /** * Table.js * Functions for interactive Tables * * Copyright (c) 2007 Matt Kruse (javascripttoolbox.com) * Dual licensed under the MIT and GPL licenses. * * @version 0.981 * * @history 0.981 2007-03-19 Added Sort.numeric_comma, additional date parsing formats * @history 0.980 2007-03-18 Release new BETA release pending some testing. Todo: Additional docs, examples, plus jQuery plugin. * @history 0.959 2007-03-05 Added more "auto" functionality, couple bug fixes * @history 0.958 2007-02-28 Added auto functionality based on class names * @history 0.957 2007-02-21 Speed increases, more code cleanup, added Auto Sort functionality * @history 0.956 2007-02-16 Cleaned up the code and added Auto Filter functionality. * @history 0.950 2006-11-15 First BETA release. * * @todo Add more date format parsers * @todo Add style classes to colgroup tags after sorting/filtering in case the user wants to highlight the whole column * @todo Correct for colspans in data rows (this may slow it down) * @todo Fix for IE losing form control values after sort? */ /** * Sort Functions */ var Sort = (function(){ var sort = {}; // Default alpha-numeric sort // -------------------------- sort.alphanumeric = function(a,b) { return (a==b)?0:(a0) { var rows = section.rows; for (var j=0,L2=rows.length; j0) { var cells = row.cells; for (var k=0,L3=cells.length; k1 && cells[cells.length-1].cellIndex>0) { // Define the new function, overwrite the one we're running now, and then run the new one (this.getCellIndex = function(td) { return td.cellIndex; })(td); } // Safari will always go through this slower block every time. Oh well. for (var i=0,L=cells.length; i=0 && node.options) { // Sort select elements by the visible text return node.options[node.selectedIndex].text; } return ""; }, 'IMG':function(node) { return node.name || ""; } }; /** * Get the text value of a cell. Only use innerText if explicitly told to, because * otherwise we want to be able to handle sorting on inputs and other types */ table.getCellValue = function(td,useInnerText) { if (useInnerText && def(td.innerText)) { return td.innerText; } if (!td.childNodes) { return ""; } var childNodes=td.childNodes; var ret = ""; for (var i=0,L=childNodes.length; i-1) { filters={ 'filter':filters.options[filters.selectedIndex].value }; } // Also allow for a regular input if (filters.nodeName=="INPUT" && filters.type=="text") { filters={ 'filter':"/^"+filters.value+"/" }; } // Force filters to be an array if (typeof(filters)=="object" && !filters.length) { filters = [filters]; } // Convert regular expression strings to RegExp objects and function strings to function objects for (var i=0,L=filters.length; ipageend) { hideRow = true; } } } row.style.display = hideRow?"none":""; } } if (def(page)) { // Check to see if filtering has put us past the requested page index. If it has, // then go back to the last page and show it. if (pagestart>=unfilteredrowcount) { pagestart = unfilteredrowcount-(unfilteredrowcount%pagesize); tdata.page = page = pagestart/pagesize; for (var i=pagestart,L=unfilteredrows.length; i0) { if (typeof(args.insert)=="function") { func.insert(cell,colValues); } else { var sel = ''; cell.innerHTML += "
"+sel; } } } }); if (val = classValue(t,table.FilteredRowcountPrefix)) { tdata.container_filtered_count = document.getElementById(val); } if (val = classValue(t,table.RowcountPrefix)) { tdata.container_all_count = document.getElementById(val); } }; /** * Attach the auto event so it happens on load. * use jQuery's ready() function if available */ if (typeof(jQuery)!="undefined") { jQuery(table.auto); } else if (window.addEventListener) { window.addEventListener( "load", table.auto, false ); } else if (window.attachEvent) { window.attachEvent( "onload", table.auto ); } return table; })();