Home > Web Front-end > JS Tutorial > Example code for moving js table rows up and down

Example code for moving js table rows up and down

零下一度
Release: 2017-06-24 14:47:07
Original
1760 people have browsed it
<script type="text/javascript">
   function tagPosition() {
      $('#easyTables').tabs('select', '输出方式');
      var rows = $('#dgTag').datagrid('getRows');//获取当前页的数据行
      //var ary = new Array();
      var ary = "";
      for (var i = 0; i < rows.length; i++) {
         ary += rows[i][&#39;id&#39;]+",";
      }
      ary=ary.substring(0,ary.length-1);

      $.ajax({
         url:&#39;../../modelFilter/Position&#39;,
         type:&#39;POST&#39;,
         data:{"ary" : ary},
         success: function(result){
            console.log(ary);
         }
      });
   }

   //上移动
   function datagridRowMove( isUp) {
      var rows=$(&#39;#dgTag&#39;).datagrid(&#39;getRows&#39;);
      var rowlength=rows.length;
      var selectrow=$(&#39;#dgTag&#39;).datagrid(&#39;getSelected&#39;);
      var rowIndex=$(&#39;#dgTag&#39;).datagrid(&#39;getRowIndex&#39;, selectrow);
      if(rowIndex==0){
         $.messager.alert(&#39;提示&#39;, &#39;顶行无法上移!&#39;, &#39;warning&#39;);
      }else{
         $(&#39;#dgTag&#39;).datagrid(&#39;deleteRow&#39;, rowIndex);//删除一行
         rowIndex--;
         $(&#39;#dgTag&#39;).datagrid(&#39;insertRow&#39;, {
            index:rowIndex,
            row:selectrow
         });
         $(&#39;#dgTag&#39;).datagrid(&#39;selectRow&#39;, rowIndex);
      }
   }
   //下移动
   function datagridRowMove1( isUp) {
      var rows=$(&#39;#dgTag&#39;).datagrid(&#39;getRows&#39;);
      var rowlength=rows.length;
      var selectrow=$(&#39;#dgTag&#39;).datagrid(&#39;getSelected&#39;);
      var rowIndex=$(&#39;#dgTag&#39;).datagrid(&#39;getRowIndex&#39;, selectrow);

         $(&#39;#dgTag&#39;).datagrid(&#39;deleteRow&#39;, rowIndex);//删除一行
         rowIndex++;
         $(&#39;#dgTag&#39;).datagrid(&#39;insertRow&#39;, {
            index:rowIndex,
            row:selectrow
         });
         $(&#39;#dgTag&#39;).datagrid(&#39;selectRow&#39;, rowIndex);
      if(rowIndex>=rowlength){
         $.messager.alert('提示', '最后一行无法下移!', 'warning');
      }
   }
</script>
Copy after login
添加onclick="tagPosition()"

后台保存移动后数据
Copy after login
@RequestMapping(value = "/Position", method = RequestMethod.POST)
@ResponseBody
public void position(String ary){
   if (ary !=null && !ary.equals("")) {
      ModelTag model = new ModelTag();
      String[] arr = ary.split(",");
      try {
         for (int i = 0; i < arr.length; i++) {
            model.setId(Integer.parseInt(arr[i]));
            model.setTagPosition(i + 1);
            modelFilterManager.updataTagEncryption(model);
         }
         /*model.setId(9600);
         model.setModuleId("2017021316419558");
         model.setTagPosition(1);
         modelFilterManager.updataTagEncryption(model);*/
         System.out.println("controller  " + ary);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
Copy after login

The above is the detailed content of Example code for moving js table rows up and down. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template