• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

客户端JS表格排序---摘自微软.

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 22次 | 进入软件测试论坛讨论

领测软件测试网 /**
*表格排序
*t:表格体.例:myTable.tBodies[0]
*iRowEnd:第几行停止排序.例:myTable.tBodies[0].rows.length-1
*fReverse:升序,降序.例:true(升)false(降)
*iColumn:第几列需要排序.例 4
*/
function insertionSort(t, iRowEnd, fReverse, iColumn)
{
  var iRowInsertRow, iRowWalkRow, current, insert;

  for ( iRowInsert = 0 + 1 ; iRowInsert <= iRowEnd ; iRowInsert++ )
  {
    if (iColumn)
    {
      if( typeof(t.children[iRowInsert].children[iColumn]) != "undefined")
        textRowInsert = t.children[iRowInsert].children[iColumn].innerText;
      else
        textRowInsert = "";
    }
    else
    {
      textRowInsert = t.children[iRowInsert].innerText;
    }
        
    for ( iRowWalk = 0; iRowWalk <= iRowInsert ; iRowWalk++ )
    {
      if (iColumn)
      {
        if(typeof(t.children[iRowWalk].children[iColumn]) != "undefined")
          textRowCurrent = t.children[iRowWalk].children[iColumn].innerText;
        else
          textRowCurrent = "";
      }
      else
      {
        textRowCurrent = t.children[iRowWalk].innerText;
      }

    //
    // We save our values so we can manipulate the numbers for
    // comparison
    //
      current = textRowCurrent;
      insert  = textRowInsert;

    //  If the value is not a number, we sort normally, else we evaluate    
    //  the value to get a numeric representation
    //

      if ( !isNaN(current) ||  !isNaN(insert))
      {
        current= eval(current);
        insert= eval(insert);
      }
      else
      {
        current=current.toLowerCase();
        insert= insert.toLowerCase();
      }

      if ( (   (!fReverse && insert < current)
               || ( fReverse && insert > current) )
           && (iRowInsert != iRowWalk) )
      {
        eRowInsert = t.children[iRowInsert];
        eRowWalk = t.children[iRowWalk];
        t.insertBefore(eRowInsert, eRowWalk);
        iRowWalk = iRowInsert; // done
      }
    }
  }
}

参考:有3个例子.各个不赖.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndude/html/dude07232001.asp

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网