Sorting Cloumns Dynamically - Java Scripts

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sorting Cloumns Dynamically - Java Scripts as PDF for free.

More details

  • Words: 723
  • Pages: 5
<style> /* sortable tables */ table.sortable a.sortheader { background-color:#eee; color:#666666; font-weight: bold; text-decoration: none; display: block; } table.sortable span.sortarrow { color: black; text-decoration: none; } <script language="javascript"> //addevent(window, "load", sortables_init); var sort_column_index; function ts_getinnertext(el) { if (typeof el == "string") return el; if (typeof el == "undefined") { return el }; if (el.innertext) return el.innertext; //not needed but it is faster var str = ""; var cs = el.childnodes; var l = cs.length; for (var i = 0; i < l; i++) { switch (cs[i].nodetype) { case 1: //element_node str += ts_getinnertext(cs[i]); break; case 3: //text_node str += cs[i].nodevalue; break; } } return str; } function ts_resorttable(lnk,coltype) { // get the span var span; for (var ci=0;ci
//if //if //if //if

(itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date; (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date; (itm.match(/^[�$]/)) sortfn = ts_sort_currency; (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;

if (coltype == "numeric") { sortfn = ts_sort_numeric; } else if (coltype == "date") { sortfn = ts_sort_date; } else if (coltype == "currency") { sortfn = ts_sort_currency; } else { sortfn = ts_sort_caseinsensitive; } sort_column_index = column; var firstrow = new array(); var newrows = new array(); for (i=0;i
} }

}

span.innerhtml = arrow; } function getparent(el, ptagname) { if (el == null) return null; else if (el.nodetype == 1 && el.tagname.tolowercase() == ptagname.tolowercase()) // gecko bug, supposed to be uppercase return el; else return getparent(el.parentnode, ptagname); } function ts_sort_date(a,b) { //window.alert("sort_date called"); // y2k notes: two digit years less than 50 are treated as 20xx, greater than 50 are treated as 19xx aa = ts_getinnertext(a.cells[sort_column_index]); bb = ts_getinnertext(b.cells[sort_column_index]); // // // // // // // // // // // // // //

}

if (aa.length == 10) { dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2); } else { yr = aa.substr(6,2); if (parseint(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } dt1 = yr+aa.substr(3,2)+aa.substr(0,2); } if (bb.length == 10) { dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2); } else { yr = bb.substr(6,2); if (parseint(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } dt2 = yr+bb.substr(3,2)+bb.substr(0,2); } dt1 = date.parse(aa); dt2 = date.parse(bb); if (dt1==dt2) return 0; if (dt1
function ts_sort_currency(a,b) { //window.alert("sort_currency called"); aa = ts_getinnertext(a.cells[sort_column_index]).replace(/[^0-9.]/g,''); bb = ts_getinnertext(b.cells[sort_column_index]).replace(/[^0-9.]/g,''); return parsefloat(aa) - parsefloat(bb); } function ts_sort_numeric(a,b) { //window.alert("sort_numeric called"); aatemp = ts_getinnertext(a.cells[sort_column_index]); aa = parsefloat(aatemp.replace(/,/gi,"")); if (isnan(aa)) aa = 0;

}

bbtemp = ts_getinnertext(b.cells[sort_column_index]); bb = parsefloat(bbtemp.replace(/,/gi,"")); if (isnan(bb)) bb = 0; if (aa==bb) return 0; if (aa
function ts_sort_caseinsensitive(a,b) { //window.alert("sort_caseinsensitive called"); aa = ts_getinnertext(a.cells[sort_column_index]).tolowercase(); bb = ts_getinnertext(b.cells[sort_column_index]).tolowercase(); if (aa==bb) return 0; if (aa

**************************************** end of the function*************************** // now another html tag for calling the above function for numeric type column: // for non-numeric columns // this is to call the function for indication arrow mark in the coulmn header

down/up) <span class="sortarrow">   

Related Documents

Java Scripts
November 2019 7
Scripts
November 2019 27
Sorting
May 2020 22