手动排序(javascript)


手工排序




---------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>start</title>
      <LINK rel="stylesheet" href="../../css/main.css" type="text/css">
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
  <body MS_POSITIONING="GridLayout">
  <FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT>
  <BR>
  <table width="200" border="0" align="center">
   <tr>
    <td class="Title" align="center" nowrap>
     手工排序
    </td>
   </tr>
  </table>
  <BR>
  <form id="Form1" method="post" action="do.asp">
    <table align="center">
      <tr align=center>
        <td width=160><select size=10 name="list1" style="width:120">
          <option value=1>1111111</option>
          <option value=2>2222222</option>
          <option value=3>3333333</option>
          <option value=4>4444444</option>
          <option value=5>5555555</option>
          <option value=6>6666666</option>
          <option value=7>7777777</option>
        </select></td>
        <td><input type="button" value="增 加>>>" οnclick="add()">
            <br/>
            <br/>
            <input type="button" value="<<<删 除" οnclick="del()">
        </td>
        <td width=79><select name="seqItem" id="seqItem" size="10" style="width:120">
        </select></td>
        <td width=79><p align="center">
          <input type="button" value="移动到顶部" onClick="doTopItem()">
        </p>
        <p align="center">
          <input type="button" name="Submit" value="向上移动" onClick="doUpItem()">
        </p>
        <p align="center">
          <input type="button" name="Submit" value="向下移动" onClick="doDownItem()" >
        </p>
        <p align="center">
          <input type="button" name="Submit" value="移动到底部" onClick="doBottomItem()">
        </p></td>
      </tr>
    </table>
    <div align="center">
      <input type="button" value="测 试" onClick="goClick()">
      <input type="button" value="重 置" onClick="doRe()">
      <input type="submit" name="ok" value="提 交">
  </div>
  </form>
 <SCRIPT LANGUAGE="javascript">
 var seqSelect=document.forms[0].seqItem;
 var length=5;
 
 //go top
 function doTopItem(){
  var length=seqSelect.options.length; 
 var topV,topT;
 var tempV=new Array();
 var tempT=new Array();
 for(var i=0;i<length;i++){
  if(seqSelect.options[i].selected){
    if(i==0)
     return false;
   topV=seqSelect.options[0].value;
    topT=seqSelect.options[0].text;
    seqSelect.options[0].value=seqSelect.options[i].value;
    seqSelect.options[0].text=seqSelect.options[i].text;
   
    for(var j=1;j<length;j++){
     tempV[j]=seqSelect.options[j].value;
     tempT[j]=seqSelect.options[j].text;
     alert(tempV+"  ··· "+tempT);
     if(j==1){
     seqSelect.options[1].value=topV;
     seqSelect.options[1].text=topT;
     }
     else if(j>i){
        break;    
     }
        else{
     seqSelect.options[j].value=tempV[j-1];
     seqSelect.options[j].text=tempT[j-1];
     }
    }
   
    }
 }
 seqSelect.options[0].selected=true;
 }
 
 //go bottom
 function doBottomItem(){ 
  var length=seqSelect.options.length;
    var bottomV,bottomT;
 var tempV=new Array();
 var tempT=new Array();
 for(var i=0;i<length;i++){
  if(seqSelect.options[i].selected){
    if(i==(length-1))
     return false;
    bottomV=seqSelect.options[length-1].value;
    bottomT=seqSelect.options[length-1].text;
    seqSelect.options[length-1].value=seqSelect.options[i].value;
    seqSelect.options[length-1].text=seqSelect.options[i].text;
   
     for(var j=length-2;j>=0;j--){
    tempV[j]=seqSelect.options[j].value;
     tempT[j]=seqSelect.options[j].text;
     alert(tempV+"  ··· "+tempT);
     if(j==(length-2)){
     seqSelect.options[length-2].value=bottomV;
     seqSelect.options[length-2].text=bottomT;
     }
     else if(j<i){
        break;    
     }
        else{
     seqSelect.options[j].value=tempV[j+1];
     seqSelect.options[j].text=tempT[j+1];
     }
    }
   
    }
 }
 seqSelect.options[length-1].selected=true;
 }
 
 //go up 1
 function doUpItem(){  
  var length=seqSelect.options.length;
 var tempV,tempT;
 for(var i=0;i<length;i++){
   if(seqSelect.options[i].selected){
    if(i==0)
         return false;
   tempV=seqSelect.options[i-1].value;
   tempT=seqSelect.options[i-1].text;
   seqSelect.options[i-1].value=seqSelect.options[i].value; 
   seqSelect.options[i-1].text=seqSelect.options[i].text;
   seqSelect.options[i].value=tempV; 
   seqSelect.options[i].text=tempT;
   seqSelect.options[i-1].selected=true;
   break;    
   }
 }
 }
 
 //go down 1
 function doDownItem(){
  var length=seqSelect.options.length;  
 var tempV,tempT;
 for(var i=0;i<length;i++){
   if(seqSelect.options[i].selected){
   if(i==(length-1))
        return false;
   tempV=seqSelect.options[i+1].value;
   tempT=seqSelect.options[i+1].text;
   seqSelect.options[i+1].value=seqSelect.options[i].value; 
   seqSelect.options[i+1].text=seqSelect.options[i].text;
   seqSelect.options[i].value=tempV; 
   seqSelect.options[i].text=tempT;
   seqSelect.options[i+1].selected=true;
   break;    
   }
 }
 }
 
 function doRe(){
 document.forms[0].action="";
 document.forms[0].submit();
 }
 
 function setCursor(objStyle,cursor)
    {
      objStyle.cursor = cursor;
    }
<!--
 function goClick()
 {
 
   var res ="";
 for (var i =0;i<seqSelect.options.length;i++)
 {
  if(seqSelect.options[i].selected)
  {
   res += seqSelect.options[i].index +",";
  }
 }
 
 alert(res);
 }
//-->
function add_singer(object,value,text)//添加数据
{
if(singer_exist(object,value)==false)
{
object.options.add(new Option(text,value,true,true));
return true;
}
return false;
}
function remove_singer(object,index)//删除数据
{
if(index<0)return false;
object.options.remove(index)
}
function singer_exist(object,value)//检查是否存在
{
for(var i=0;i<object.options.length; i++)
{
if(object.options[i].value==value)
return true;
}
return false;
}
function add()
{
var obj1=document.all.list1;
var index=obj1.selectedIndex;
if (index<0) return false;
value=obj1.options[index].value;
text=obj1.options[index].text;
var obj2=document.all.seqItem;
add_singer(obj2,value,text)
remove_singer(obj1,index)
}
function del()
{
var obj2=document.all.seqItem;
var index=obj2.selectedIndex;
if (index<0) return false;
value=obj2.options[index].value;
text=obj2.options[index].text;
var obj1=document.all.list1;
add_singer(obj1,value,text)
remove_singer(obj2,index)
}
</script>
  </body>
</html>
 
<script language=javascript> var seqSelect=document.forms[0].seqItem; var length=5; //go top function doTopItem(){ var length=seqSelect.options.length; var topV,topT; var tempV=new Array(); var tempT=new Array(); for(var i=0;i i){ break; } else{ seqSelect.options[j].value=tempV[j-1]; seqSelect.options[j].text=tempT[j-1]; } } } } seqSelect.options[0].selected=true; } //go bottom function doBottomItem(){ var length=seqSelect.options.length; var bottomV,bottomT; var tempV=new Array(); var tempT=new Array(); for(var i=0;i =0;j--){ tempV[j]=seqSelect.options[j].value; tempT[j]=seqSelect.options[j].text; alert(tempV+" ··· "+tempT); if(j==(length-2)){ seqSelect.options[length-2].value=bottomV; seqSelect.options[length-2].text=bottomT; } else if(j function add_singer(object,value,text)//添加数据 { if(singer_exist(object,value)==false) { object.options.add(new Option(text,value,true,true)); return true; } return false; } function remove_singer(object,index)//删除数据 { if(index<0)return false; object.options.remove(index) } function singer_exist(object,value)//检查是否存在 { for(var i=0;i
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想手动对 el-table 中选中的行进行排序,可以按照以下步骤操作: 1. 获取当前选中的行数据和排序方式。 2. 对选中的行数据进行排序。可以使用 JavaScript 中的 sort() 方法或 Lodash 库中的 orderBy() 方法等。 3. 根据排序方式,对 el-table 中的数据进行更新。可以使用 el-table 组件中的 $refs 属性获取到 el-table 实例,然后调用实例的 setTableData() 方法来更新数据。 下面是一个简单的示例代码,仅供参考: ```html <el-table ref="table" :data="tableData" :row-key="row => row.id" @row-click="handleRowClick"> <el-table-column prop="id" label="ID"></el-table-column> <el-table-column prop="name" label="Name"></el-table-column> <el-table-column prop="age" label="Age"></el-table-column> </el-table> ``` ```javascript export default { data() { return { tableData: [ { id: 1, name: 'Alice', age: 20 }, { id: 2, name: 'Bob', age: 25 }, { id: 3, name: 'Charlie', age: 30 }, { id: 4, name: 'David', age: 35 } ], selectedRows: [], sortKey: null, sortOrder: null } }, methods: { handleRowClick(row) { this.$refs.table.toggleRowSelection(row) this.selectedRows = this.$refs.table.selection }, handleSort() { if (this.sortKey && this.sortOrder) { this.selectedRows.sort((a, b) => { const sortVal = this.sortOrder === 'asc' ? 1 : -1 if (a[this.sortKey] < b[this.sortKey]) { return -sortVal } else if (a[this.sortKey] > b[this.sortKey]) { return sortVal } else { return 0 } }) const newData = this.tableData.map(row => { if (this.selectedRows.indexOf(row) > -1) { return this.selectedRows.shift() } else { return row } }) this.$refs.table.setTableData(newData) } } } } ``` 在上述示例代码中,我们定义了一个 el-table 组件,并且监听了它的 row-click 事件,以便获取选中的行数据。然后,我们定义了一个 handleSort() 方法,该方法会根据 sortKey 和 sortOrder 对选中的行数据进行排序,并更新 el-table 中的数据。注意,我们需要使用 $refs 属性获取到 el-table 实例,以便调用 setTableData() 方法来更新数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值