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

jQuery控制表格行移动,序号不变

2015-04-29 10:07 363 查看
@model Gd.NetSign.Controllers.DTO.SysPamaterDTO
@{
ViewBag.Title = "SysPamatList";
//Layout = "~/Views/Masters/Frame.cshtml";
}
<script type="text/javascript">
//检索
function doSearch() {

loading();
$.ajax({
type: "post",
url: '/Spfsz/SysPamatList?SysPamaterName=' + $('#SysPamaterName').val() + "&SysPamaterRemark=" + $('#SysPamaterRemark').val() + "&ParentKeyName=" + "@Model.ParentKeyName",
data: {},
dataType: "html",
error: function (msg) {

unloading();

},
success: function (result) {
$("#List").html(result);
unloading();

}
});

}
//-->
//保存
function DoSave() {
loading("数据提交中...请稍后");
var previewOptions = {
url: "/Spfsz/SaveSysPamat?isOder=1&ParentKeyName=" + "@Model.ParentKeyName",
type: 'POST',
//data:_list: _list,
//beforeSubmit: submitCheck,
iframe: false,
success: function (result) {
unloading();
if (result.Success == true) {

$.Ok(result.Msg, function () {
loading();
$.ajax({
type: "post",
url: "/Spfsz/SysPamatList?ParentKeyName=" + "@Model.ParentKeyName",
data: {},
dataType: "html",
error: function (msg) {

unloading();

},
success: function (result) {
$("#List").html(result);
unloading();

}
});
});
}
if (result.Success == false) {
$.Error(result.Msg);
}
},
error: function () {
unloading();
}
};
$("#OperaForm").ajaxSubmit(previewOptions);
return false;
}
//保存
function DoSaveSingle() {
loading("数据提交中...请稍后");
var previewOptions = {
url: "/Spfsz/SaveSysPamat?ParentKeyName=" + "@Model.ParentKeyName",
type: 'POST',
//data:_list: _list,
//beforeSubmit: submitCheck,
iframe: false,
success: function (result) {
unloading();
if (result.Success == true) {

$.Ok(result.Msg, function () {
loading();
$.ajax({
type: "post",
url: "/Spfsz/SysPamatList?ParentKeyName=" + "@Model.ParentKeyName",
data: {},
dataType: "html",
error: function (msg) {

unloading();

},
success: function (result) {
$("#List").html(result);
unloading();

}
});
});
}
if (result.Success == false) {
$.Error(result.Msg);
}
},
error: function () {
unloading();
}
};
$("#OperaForm").ajaxSubmit(previewOptions);
return false;
}

</script>
<style>
tr input {
border: hidden;
background-color: transparent;
width: 100%;
height: 20px;
margin-left: 2px;
}

table tr td {
text-align: left;
}
</style>

<div class="div_btnContainer">
<span>参数名:</span><input id="SysPamaterName" class="txt" type="text" value="@Model.SysPamaterName" />
<span>参数说明:</span><input id="SysPamaterRemark" class="txt" type="text" value="@Model.SysPamaterRemark" />
<input type="button" class="btn" value="检索" onclick="doSearch();" />

<input   type="button"  id="upMove"  value="上移" @(Model.IsNullField == 1 ? "class=btn" : "  class=btn_disable disabled=disabled")  onclick="up_exchange_line();" />
<input type="button" id="DmMove"  value="下移" @(Model.IsNullField == 1 ? "class=btn" : "  class=btn_disable disabled=disabled ") onclick="down_exchange_line();" />
<input type="button" class="btn" value="保存" @(Model.IsNullField == 1 ? "onclick=DoSave()" : "onclick=DoSaveSingle()") />
</div>
<form id="OperaForm" method="post" action="" enctype="multipart/form-data">
<div class="form">
<table id="floorHouse" cellpadding="1" cellspacing="1" class="tabClass">
<thead>
<tr>
<th style="width: 20px" title="选择">选择</th>
<th style="width: 50px;" title="参数名">参数名</th>
<th style="width: 100px;" title="参数值">参数值</th>
<th style="width: 300px;" title="参数说明">参数说明</th>

</tr>
</thead>
<tbody>
@{string line = "";
var listLength = Model.SysPamaterList.Count();
for (int i = 0; i < listLength; i++)
{
line = "line" + (i + 1);
<tr id="@line">

<td>
<input name="[@(i)].NodeIdx" id="subcheck" onclick="chk(this);" type="checkbox" value="@(i+1)" />
<input hidden="hidden" name="[@(i)].NodeIdx" id="NodeIdx" type="text" value="@(i+1)" />
</td>
<td title="@Model.SysPamaterList[i].KeyName" id="cknull">
<input type="text" id="KeyName" readonly="readonly" name="[@(i)].KeyName" value="@Model.SysPamaterList[i].KeyName" />
</td>
<td title="@Model.SysPamaterList[i].KeyValue" id="cknull">
<input type="text" id="KeyValue" name="[@(i)].KeyValue" value="@Model.SysPamaterList[i].KeyValue" />
</td>
<td title="@Model.SysPamaterList[i].KeyDis"  id=" cknull">
<input type="text" id="KeyDis" readonly="readonly" name="[@(i)].KeyDis" value="@Model.SysPamaterList[i].KeyDis" />
<input type="text" id="IsNewNetSign" hidden="hidden" name="[@(i)].IsNewNetSign" value="@Model.SysPamaterList[i].IsNewNetSign" />

</td>
</tr>
}
}
</tbody>
</table>

</div>
</form>

<script language="javascript">

var currentStep = new Array();
var max_line_num = parseInt("@Model.SysPamaterList.Count()");
//上移
function up_exchange_line() {
if (!checks())
return;
//升序
currentStep.sort(function (a, b) { return a > b ? 1 : -1 });
for (var i = 0; i < currentStep.length; i++) {
if (currentStep[i] == 0 || currentStep[i] == null) {
continue;
}
else {
var upStep = currentStep[i] - 1;
if (upStep < 1 || $('#line' + upStep + ' input[type="checkbox"]').attr("checked")) {
continue;
}
//取值
var keynameNext = $("#line" + upStep + " input[id='KeyName']").val();
var keyvalueNext = $("#line" + upStep + " input[id='KeyValue']").val();
var KeyDisNext = $("#line" + upStep + " input[id='KeyDis']").val();
var IsNewNetSignNext = $("#line" + upStep + " input[id='IsNewNetSign']").val();
var keyname = $("#line" + currentStep[i] + " input[id='KeyName']").val();
var keyvalue = $("#line" + currentStep[i] + " input[id='KeyValue']").val();
var KeyDis = $("#line" + currentStep[i] + " input[id='KeyDis']").val();
var IsNewNetSign = $("#line" + currentStep[i] + " input[id='IsNewNetSign']").val();
//换值
$("#line" + upStep + " input[id='KeyName']").val(keyname);
$("#line" + upStep + " input[id='KeyValue']").val(keyvalue);
$("#line" + upStep + " input[id='KeyDis']").val(KeyDis);
$("#line" + upStep + " input[id='IsNewNetSign']").val(IsNewNetSign);
$("#line" + currentStep[i] + " input[id='KeyName']").val(keynameNext);
$("#line" + currentStep[i] + " input[id='KeyValue']").val(keyvalueNext);
$("#line" + currentStep[i] + " input[id='KeyDis']").val(KeyDisNext);
$("#line" + currentStep[i] + " input[id='IsNewNetSign']").val(IsNewNetSignNext);
//修改选中
$('#line' + upStep + ' input[type="checkbox"]').attr("checked", true);
$('#line' + currentStep[i] + ' input[type="checkbox"]').attr("checked", false);
currentStep[i] = upStep;

}

}

}
//下移
function down_exchange_line() {
if (!checks())
return;
//倒序
currentStep.sort(function (a, b) { return a < b ? 1 : -1 });
for (var i = 0; i < currentStep.length; i++) {
if (currentStep[i] == "0" || currentStep[i] == null) {
continue;

}
else {

var nextStep = parseInt(currentStep[i]) + 1;
if (nextStep > max_line_num || $('#line' + nextStep + ' input[type="checkbox"]').attr("checked")) {
continue;
}
//取值
var keynameNext = $("#line" + nextStep + " input[id='KeyName']").val();
var keyvalueNext = $("#line" + nextStep + " input[id='KeyValue']").val();
var KeyDisNext = $("#line" + nextStep + " input[id='KeyDis']").val();
var IsNewNetSignNext = $("#line" + nextStep + " input[id='IsNewNetSign']").val();
var keyname = $("#line" + currentStep[i] + " input[id='KeyName']").val();
var keyvalue = $("#line" + currentStep[i] + " input[id='KeyValue']").val();
var KeyDis = $("#line" + currentStep[i] + " input[id='KeyDis']").val();
var IsNewNetSign = $("#line" + currentStep[i] + " input[id='IsNewNetSign']").val();
//换值
$("#line" + nextStep + " input[id='KeyName']").val(keyname);
$("#line" + nextStep + " input[id='KeyValue']").val(keyvalue);
$("#line" + nextStep + " input[id='KeyDis']").val(KeyDis);
$("#line" + nextStep + " input[id='IsNewNetSign']").val(IsNewNetSign);
$("#line" + currentStep[i] + " input[id='KeyName']").val(keynameNext);
$("#line" + currentStep[i] + " input[id='KeyValue']").val(keyvalueNext);
$("#line" + currentStep[i] + " input[id='KeyDis']").val(KeyDisNext);
$("#line" + currentStep[i] + " input[id='IsNewNetSign']").val(IsNewNetSignNext);
//修改选中
$('#line' + nextStep + ' input[type="checkbox"]').attr("checked", true);
$('#line' + currentStep[i] + ' input[type="checkbox"]').attr("checked", false);
currentStep[i] = nextStep;

}
}
}
//增加减少id值
function chk(box) {
if ($(box).attr("checked") == "checked") {
//currentStep.push($(box).parent().parent().find("td").eq(0).text())
currentStep.push(parseInt($(box).val()));
}
else {

for (var i = 0; i < currentStep.length; i++) {
if (currentStep[i] == $(box).val()) {
currentStep.remove(i);
//.remove(i);
}

}

}

}
Array.prototype.remove = function (dx) {
if (isNaN(dx) || dx > this.length) { return false; }
for (var i = 0, n = 0; i < this.length; i++) {
if (this[i] != this[dx]) {
this[n++] = this[i]
}
}
this.length -= 1
}
function checks() {
var chk_value = [];
$('input:checked').each(function () {
chk_value.push($(this).val());
});
if (chk_value.length <= 0) {
//alert("请选择一条数据");
$.Warning('请选择一条数据!');
return false;

}
return true;
}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: