您的位置:首页 > Web前端 > JQuery

jquery 中的table sort控制

2013-11-05 11:02 253 查看
前段table Header

 

<thead id ="tablehe" style="display:none">
<tr id="tablehead">
<th class="tabhead" width="15%"><div sortname="companyName" class="">Company</div></th>
<th class="tabhead tabhead_on" width="15%"><div sortname="opportunityName" class="arrowdiv_up">Title</div></th>
<th class="tabhead" width="16%"><div sortname="pursuitLeaderName" class="">Pursuit Leader</div></th>
<th class="tabhead" width="10%"><div sortname="service" class="">Service</div></th>
<th class="tabhead" width="11%"><div sortname="probability" class="">Probability</div></th>
<th class="tabhead" width="12%"><div  sortname="salesStage" class="">Sales Stage</div></th>
<th class="tabhead" width="11%"><div sortname="closeDate" class="">Close date</div></th>
<th class="tabhead" colspan="2" width="20%"><div sortname="tcv" class="">TCV</div></th>
</tr>
</thead>


js代码

function registerSortable(){
$("#tablehead").children().each(function(i,e){
$(this).click(function(d){

$(this).siblings().children("div").removeClass("arrowdiv_up");
$(this).siblings().children("div").removeClass("arrowdiv_down");
$(this).siblings("th").removeClass("tabhead_on");
$(this).addClass("tabhead_on");

var sortASC;
var div = $(this).find("div:eq(0)");
var  sortClumn = div.attr("sortname");
if(!div.hasClass("arrowdiv_down") && !div.hasClass("arrowdiv_up")){
div.addClass("arrowdiv_up");
sortAsc = true;
}else{
if(div.hasClass("arrowdiv_down")){
div.removeClass("arrowdiv_down");
div.addClass("arrowdiv_up");
sortAsc = true;
}else if(div.hasClass("arrowdiv_up")){
div.removeClass("arrowdiv_up");
div.addClass("arrowdiv_down");
sortAsc = false;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: