欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

/**
*表格排序
*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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 客户端JS表格排序—摘自微软.
分享到: 更多 (0)

相关推荐

  • 暂无文章