码迷,mamicode.com
首页 > 编程语言 > 详细

排序插件jquery.ui.sortable

时间:2015-03-20 09:14:03      阅读:484      评论:0      收藏:0      [点我收藏+]

标签:

<link href="${base}/resources/sort/jquery.ui.all.css" rel="stylesheet"
    type="text/css" />
<script type="text/javascript" src="${base}/page/js/jquery.js"></script>
<script type="text/javascript"
    src="${base}/resources/sort/jquery.ui.core.js"></script>
<script type="text/javascript"
    src="${base}/resources/sort/jquery.ui.widget.js"></script>
<script type="text/javascript"
    src="${base}/resources/sort/jquery.ui.mouse.js"></script>
<script type="text/javascript"
    src="${base}/resources/sort/jquery.ui.sortable.js"></script>


<script type="text/javascript">
    $(document).ready(function() {
        //是否开启排序
        var isSort=false;
        //#sortTable为需要排序的表格
        $("#sortTable tbody").sortable({
            //helper对象为sortable方法返回的对象
            helper:function(e,ele){
                //获得子对象
                var _origianl=ele.children();
                //克隆对象
                var _helper=ele.clone();
                _helper.children().each(function(index){
                    //根据不同的下标设置宽度
                    $(this).width(_origianl.eq(index).width());
                });
                //改变选中的背景色
                _helper.css("background","#eef")
                return _helper;
            },
            //更新时设置序号
            update:function(e,u){
                setOrders();
            },
            //拖动方向
            axis:"y"
        });
        //初始化时禁用排序功能
        $("#sortTable tbody").sortable("disable");
        //点击排序后
        $("#order").click(function(){
            if(!isSort){
                //追加一列
                $("#sortTable thead tr").append("<th>序号</th>");
                //设置排序
                setOrders();
                //改变文字
                $("#order").html("<span><img src=‘${base}/page/images/t04.png‘ />"+"</span>保存排序");
                //启用排序
                $("#sortTable tbody").sortable("enable");
                //更改状态
                isSort=true;
            }else{
                //获得排序后的需要[需要给tr一个id="id_${c.id}"属性]
                var ids=$("#sortTable tbody").sortable("serialize",{key:"ids"});
                //发请求保存排序后的表格
                $.post("http://localhost:8080/Yuxinglab/admin/channel/updateSort.jhtml?"+ids,function(data){
                    if(data.result){
                        $("#order").html("<span><img src=‘${base}/page/images/t04.png‘ />"+"</span>开始排序");
                        $("#sortTable tbody").sortable("disable");
                        $("#sortTable tr").each(function(){
                            $(this).children().last().remove();
                        });
                        isSort=false;
                        alert("排序保存成功");
                    }else{
                        alert(data.msg)
                    }
                    
                });
                
                
            }
            
        });
        
        
        
        function setOrders(){
            $("#sortTable tbody tr").each(function(index){
                if(isSort){
                    $(this).find("td:last").html((index+1));
                }else{
                    $(this).append("<td>"+(index+1)+"</td>");
                }
                
            });
        }
        $(".click").click(function() {
            $(".tip").fadeIn(200);
        });

        $(".tiptop a").click(function() {
            $(".tip").fadeOut(200);
        });

        $(".sure").click(function() {
            $(".tip").fadeOut(100);
        });

        $(".cancel").click(function() {
            $(".tip").fadeOut(100);
        });

    });
</script>
<table class="tablelist" id="sortTable">
            <thead>
                <tr>
                    <th><input name="" type="checkbox" value="" checked="checked" />
                    </th>
                    <th>编号<class="sort"><img
                            
src="${base}/page/images/px.gif" />
                    </i>
                    </th>
                    <th>栏目名称</th>
                    <th>栏目路径</th>
                    <th>栏目类型</th>
                    <th>列表页模板</th>
                    <th>内容页模板</th>
                    <th>是否为外部链接</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody >
                [#list channels as c]
                <tr id="id_${c.id}">
                    <td><input name="" type="checkbox" value="" />
                    </td>
                    <td>${c.id}</td>
                    <td>${c.name}</td>
                    <td>${c.path}</td>
                    <td>${c.channelType}</td>
                    <td>${c.listTemplate!}</td>
                    <td>${c.detailTemplate!}</td>

                    <td>[#if c.isURL==1] 是 [#else] 否 [/#if]</td>
                    <td><href="#" class="tablelink">查看</a> <href="${base}/admin/channel/delete.jhtml?id=${c.id}&pid=${parentChannel.id}"
                        class
="tablelink" onclick=""> 删除</a>
                    </td>
                </tr>
                [/#list]

            </tbody>
        </table>

排序插件jquery.ui.sortable

标签:

原文地址:http://www.cnblogs.com/yuxinglab/p/4352719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!