javascript table排序 这个更简单了,不用改变现在的表格结构
2010-04-23 00:00
766 查看
JavaScript实现可自定义排序的表格 -
BODY {
FONT-SIZE: 0.8em; FONT-FAMILY: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif
}
P {
FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px
}
.tableWidget_headerCell {
BORDER-RIGHT: #aca899 1px solid; BORDER-LEFT: #fff 1px solid; CURSOR: pointer; BORDER-BOTTOM: #c5c2b2 3px solid; BACKGROUND-COLOR: #ece9d8
}
.tableWigdet_headerCellOver {
BORDER-RIGHT: #aca899 1px solid; BORDER-LEFT: #fff 1px solid; CURSOR: pointer; BORDER-BOTTOM: #c5c2b2 3px solid; BACKGROUND-COLOR: #ece9d8
}
.tableWigdet_headerCellDown {
BORDER-RIGHT: #aca899 1px solid; BORDER-LEFT: #fff 1px solid; CURSOR: pointer; BORDER-BOTTOM: #c5c2b2 3px solid; BACKGROUND-COLOR: #ece9d8
}
.tableWidget_headerCell {
BORDER-TOP: #ece9d8 2px solid
}
.tableWigdet_headerCellOver {
BORDER-TOP: #ffc83c 2px solid
}
.tableWidget TBODY .tableWidget_dataRollOver {
BACKGROUND-COLOR: #fff
}
.tableWigdet_headerCellDown {
BORDER-RIGHT: #fff 1px solid; BORDER-TOP: #ffc83c 2px solid; BORDER-LEFT: #aca899 1px solid; BACKGROUND-COLOR: #dbd8c5
}
.tableWidget TD {
PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; MARGIN: 0px; PADDING-TOP: 2px; BORDER-BOTTOM: #eae9e1 1px solid
}
.tableWidget TBODY {
BACKGROUND-COLOR: #fff
}
.tableWidget {
FONT-SIZE: 12px; WIDTH: 400px; FONT-FAMILY: arial
}
DIV.widget_tableDiv {
BORDER-RIGHT: #aca899 1px solid; BORDER-TOP: #aca899 1px solid; OVERFLOW-Y: auto; BORDER-LEFT: #aca899 1px solid; WIDTH: 400px; BORDER-BOTTOM: #aca899 1px solid; HEIGHT: 200px
}
HTML > BODY DIV.widget_tableDiv {
OVERFLOW: hidden; WIDTH: 400px
}
.tableWidget THEAD {
POSITION: relative
}
.tableWidget THEAD TR {
BOTTOM: 0px; POSITION: relative; TOP: 0px
}
.tableWidget .scrollingContent {
OVERFLOW-Y: auto; WIDTH: 100%
}
/*
(C) www.dhtmlgoodies.com, October 2005
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
Thank you!
www.dhtmlgoodies.com
Alf Magne Kalleland
*/
var tableWidget_tableCounter = 0;
var tableWidget_arraySort = new Array();
var tableWidget_okToSort = true;
var activeColumn = new Array();
var arrowImagePath = "images/"; // Path to arrow images
function addEndCol(obj)
{
if(document.all)return;
var rows = obj.getElementsByTagName('TR');
for(var no=0;no=0)a = eval(a);
if(b.indexOf('/')>=0)b = eval(b);
return a/1 - b/1;
}
function sortString(a, b) {
if ( a.toUpperCase() < b.toUpperCase() ) return -1;
if ( a.toUpperCase() > b.toUpperCase() ) return 1;
return 0;
}
function cancelTableWidgetEvent()
{
return false;
}
function sortTable()
{
if(!tableWidget_okToSort)return;
tableWidget_okToSort = false;
/* Getting index of current column */
var obj = this;
var indexThis = 0;
while(obj.previousSibling){
obj = obj.previousSibling;
if(obj.tagName=='TD')indexThis++;
}
var images = this.getElementsByTagName('IMG');
if(this.getAttribute('direction') || this.direction){
direction = this.getAttribute('direction');
if(navigator.userAgent.indexOf('Opera')>=0)direction = this.direction;
if(direction=='ascending'){
direction = 'descending';
this.setAttribute('direction','descending');
this.direction = 'descending';
}else{
direction = 'ascending';
this.setAttribute('direction','ascending');
this.direction = 'ascending';
}
}else{
direction = 'ascending';
this.setAttribute('direction','ascending');
this.direction = 'ascending';
}
if(direction=='descending'){
images[0].style.display='inline';
images[0].style.visibility='visible';
images[1].style.display='none';
}else{
images[1].style.display='inline';
images[1].style.visibility='visible';
images[0].style.display='none';
}
var tableObj = this.parentNode.parentNode.parentNode;
var tBody = tableObj.getElementsByTagName('TBODY')[0];
var widgetIndex = tableObj.id.replace(/[^\d]/g,'');
var sortMethod = tableWidget_arraySort[widgetIndex][indexThis]; // N = numeric, S = String
if(activeColumn[widgetIndex] && activeColumn[widgetIndex]!=this){
var images = activeColumn[widgetIndex].getElementsByTagName('IMG');
images[0].style.display='none';
images[1].style.display='inline';
images[1].style.visibility = 'hidden';
if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');
}
activeColumn[widgetIndex] = this;
var cellArray = new Array();
var cellObjArray = new Array();
for(var no=1;no=0;no--){
for(var no2=0;no2
BODY {
FONT-SIZE: 0.8em; FONT-FAMILY: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif
}
P {
FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px
}
.tableWidget_headerCell {
BORDER-RIGHT: #aca899 1px solid; BORDER-LEFT: #fff 1px solid; CURSOR: pointer; BORDER-BOTTOM: #c5c2b2 3px solid; BACKGROUND-COLOR: #ece9d8
}
.tableWigdet_headerCellOver {
BORDER-RIGHT: #aca899 1px solid; BORDER-LEFT: #fff 1px solid; CURSOR: pointer; BORDER-BOTTOM: #c5c2b2 3px solid; BACKGROUND-COLOR: #ece9d8
}
.tableWigdet_headerCellDown {
BORDER-RIGHT: #aca899 1px solid; BORDER-LEFT: #fff 1px solid; CURSOR: pointer; BORDER-BOTTOM: #c5c2b2 3px solid; BACKGROUND-COLOR: #ece9d8
}
.tableWidget_headerCell {
BORDER-TOP: #ece9d8 2px solid
}
.tableWigdet_headerCellOver {
BORDER-TOP: #ffc83c 2px solid
}
.tableWidget TBODY .tableWidget_dataRollOver {
BACKGROUND-COLOR: #fff
}
.tableWigdet_headerCellDown {
BORDER-RIGHT: #fff 1px solid; BORDER-TOP: #ffc83c 2px solid; BORDER-LEFT: #aca899 1px solid; BACKGROUND-COLOR: #dbd8c5
}
.tableWidget TD {
PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; MARGIN: 0px; PADDING-TOP: 2px; BORDER-BOTTOM: #eae9e1 1px solid
}
.tableWidget TBODY {
BACKGROUND-COLOR: #fff
}
.tableWidget {
FONT-SIZE: 12px; WIDTH: 400px; FONT-FAMILY: arial
}
DIV.widget_tableDiv {
BORDER-RIGHT: #aca899 1px solid; BORDER-TOP: #aca899 1px solid; OVERFLOW-Y: auto; BORDER-LEFT: #aca899 1px solid; WIDTH: 400px; BORDER-BOTTOM: #aca899 1px solid; HEIGHT: 200px
}
HTML > BODY DIV.widget_tableDiv {
OVERFLOW: hidden; WIDTH: 400px
}
.tableWidget THEAD {
POSITION: relative
}
.tableWidget THEAD TR {
BOTTOM: 0px; POSITION: relative; TOP: 0px
}
.tableWidget .scrollingContent {
OVERFLOW-Y: auto; WIDTH: 100%
}
/*
(C) www.dhtmlgoodies.com, October 2005
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
Thank you!
www.dhtmlgoodies.com
Alf Magne Kalleland
*/
var tableWidget_tableCounter = 0;
var tableWidget_arraySort = new Array();
var tableWidget_okToSort = true;
var activeColumn = new Array();
var arrowImagePath = "images/"; // Path to arrow images
function addEndCol(obj)
{
if(document.all)return;
var rows = obj.getElementsByTagName('TR');
for(var no=0;no=0)a = eval(a);
if(b.indexOf('/')>=0)b = eval(b);
return a/1 - b/1;
}
function sortString(a, b) {
if ( a.toUpperCase() < b.toUpperCase() ) return -1;
if ( a.toUpperCase() > b.toUpperCase() ) return 1;
return 0;
}
function cancelTableWidgetEvent()
{
return false;
}
function sortTable()
{
if(!tableWidget_okToSort)return;
tableWidget_okToSort = false;
/* Getting index of current column */
var obj = this;
var indexThis = 0;
while(obj.previousSibling){
obj = obj.previousSibling;
if(obj.tagName=='TD')indexThis++;
}
var images = this.getElementsByTagName('IMG');
if(this.getAttribute('direction') || this.direction){
direction = this.getAttribute('direction');
if(navigator.userAgent.indexOf('Opera')>=0)direction = this.direction;
if(direction=='ascending'){
direction = 'descending';
this.setAttribute('direction','descending');
this.direction = 'descending';
}else{
direction = 'ascending';
this.setAttribute('direction','ascending');
this.direction = 'ascending';
}
}else{
direction = 'ascending';
this.setAttribute('direction','ascending');
this.direction = 'ascending';
}
if(direction=='descending'){
images[0].style.display='inline';
images[0].style.visibility='visible';
images[1].style.display='none';
}else{
images[1].style.display='inline';
images[1].style.visibility='visible';
images[0].style.display='none';
}
var tableObj = this.parentNode.parentNode.parentNode;
var tBody = tableObj.getElementsByTagName('TBODY')[0];
var widgetIndex = tableObj.id.replace(/[^\d]/g,'');
var sortMethod = tableWidget_arraySort[widgetIndex][indexThis]; // N = numeric, S = String
if(activeColumn[widgetIndex] && activeColumn[widgetIndex]!=this){
var images = activeColumn[widgetIndex].getElementsByTagName('IMG');
images[0].style.display='none';
images[1].style.display='inline';
images[1].style.visibility = 'hidden';
if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');
}
activeColumn[widgetIndex] = this;
var cellArray = new Array();
var cellObjArray = new Array();
for(var no=1;no=0;no--){
for(var no2=0;no2
相关文章推荐
- javascript table排序 这个更简单了,不用改变现在的表格结构
- javascript table排序 这个更简单了,不用改变现在的表格结构
- 另外一个table排序,这个更简单了,不用改变现在的表格结构
- javascript实现简单的table表格排序特效
- 原生javascript实现拖拽改变table表格行高(html)
- javascript 表格内容排序 简单操作示例代码
- javascript 表格排序和表头浮动效果(扩展SortTable)
- javascript小组件 原生table排序表格脚本(兼容ie firefox opera chrome)
- JavaScript -- 控制table的创建 与 删除, 排序, 表格颜色
- Auntion-TableSort国人写的一个javascript表格排序的东西
- JavaScript控制网页内表格TABLE排序
- table根据表格内的元素改变行颜色的javascript实现
- 用Javascript进行简单的Table点击排序
- table表格js简单操作隐藏与显示出现结构错乱解决方法
- JavaScript -- 控制table的创建 与 删除, 排序, 表格颜色
- javascript小组件 原生table排序表格脚本(兼容ie firefox opera chrome)
- 原生态 JavaScript 动态创建任意行数和列数的表格简单脚本 (简单Table ,object)
- 通过javascript实现table表格排序分页功能(转)
- JavaScript控制网页内表格TABLE排序