html代码:
<th class="sork" id="totalSork" onclick="clickSork(0, $(this))">当日接入数据总量 <img src="~/Images/descending.png" style="25px;" /></th> <th class="sork" id="overSork" onclick="clickSork(2, $(this))">当日超限数据量 <img src="~/Images/descending.png" style="25px;" /></th> <th class="sork" id="timeSork" onclick="clickSork(4, $(this))">上一次接入数据时间 <img src="~/Images/descending.png" style="25px;" /></th>
js代码:
给你所要排序的字段赋值:
var total = [], acTime = [], over = [],dataSork = 0; function chart(){//赋值方法 $.ajax({ url: "/aa/QueryData", data: { pageIndex: pageIndex, sork: dataSork//排序参数 }, type: "POST", dataType: "JSON", beforeSend: function () { layer.load(1, { offset: ['50%', "50%"], shade: false }); }, success: function (data) { showloading(false); total = [], acTime = [], over = []; if (data.infoList.length > 0) { for (var i = 0; i < data.infoList.length; i++) { total.push(data.infoList[i].totalCarNum); over.push(data.infoList[i].overCarNum); acTime.push(data.infoList[i].dcAcceptTime); } } } }) } 排序方法: List<OverCaseData> listdata = new List<OverCaseData>(); //排序 function clickSork(val, e) { if (!isSork) { isSork = true; if (e.children()[0].src.indexOf('descending_pitch') > 0) { e.children()[0].src = "../Images/ascending_pitch.png"; dataSork = val + 1; } else if (e.children()[0].src.indexOf('descending') > 0) { e.children()[0].src = "../Images/descending_pitch.png"; dataSork = val; } else { e.children()[0].src = "../Images/descending_pitch.png"; dataSork = val; } var sork = document.getElementsByClassName("sork"); for (var i = 0; i < sork.length; i++) { if (sork[i].id != e[0].id) { sork[i].children[0].src = "../Images/descending.png"; } } chart(0, 1);//刷新 } else { layer.msg('请稍后再试...'); } }
后台代码:
switch (param.Sork) { case 1://过车总数升序 listdata = dataList.OrderBy(v => v.totalCarNum).ToList(); break; case 2://超限总数升序 listdata = dataList.OrderBy(v => v.overCarNum).ToList(); break; case 3://超限总数降序 listdata = dataList.OrderByDescending(v => v.overCarNum).ToList(); break; case 4://接收时间升序 listdata = dataList.OrderBy(v => v.dcAcceptTime).ToList(); break; case 5://接收时间降序 listdata = dataList.OrderByDescending(v => v.dcAcceptTime).ToList(); break; default: listdata = dataList.OrderByDescending(v => v.totalCarNum).ThenByDescending(v => v.overCarNum).ThenByDescending(v => v.dcAcceptTime).ThenByDescending(v => v.timeState).ThenByDescending(v => v.onLineTime).ThenByDescending(v => v.offLineTime).ToList(); break; }