全编辑WebGrid控件LrcGrid(4)—— 脚本库和样式表
脚本库:包含了控件客户端操作的函数.包括:
将表格行切换到编辑模式的函数:chgEditRow(rowIndex,tab)()
将表格列切换到编辑模式的函数:chgEdit(colIndex,tab)
在客户端构造更新数据库的sql语句: BuildSql(tabName)
添加新记录的函数:AddRow(tab)
移除新添加行的函数: RemoveRow(tab)
全部js代码:
function chgEditRow(rowIndex,tab)
{
var tabBody = tab.tBodies[0];
var isE = 0;
//alert(rowIndex);
//alert(tabBody.rows[rowIndex].cells.length);
for(var i = 0;i< tabBody.rows[rowIndex].cells.length;i++)
{
//alert(tabBody.rows[rowIndex].cells[i].childNodes[0].id);
if(tabBody.rows[rowIndex].cells[i].hasChildNodes())
{
if(tabBody.rows[rowIndex].cells[i].childNodes[0].nodeType != 3)
{
if(tabBody.rows[rowIndex].cells[i].childNodes[0].id.indexOf('LrcTb_') != -1)
{
if(!tabBody.rows[rowIndex].cells[i].childNodes[0].disabled)
{
tabBody.rows[rowIndex].cells[i].childNodes[0].disabled = true;
tabBody.rows[rowIndex].cells[i].childNodes[0].className = "lrc_txt_hid";
}
else
{
tabBody.rows[rowIndex].cells[i].childNodes[0].disabled = false;
tabBody.rows[rowIndex].cells[i].childNodes[0].className = "lrc_txt_show";
}
}
else if(tabBody.rows[rowIndex].cells[i].childNodes[0].id.indexOf('LrcDrl_') != -1)
{
if(!tabBody.rows[rowIndex].cells[i].childNodes[0].disabled)
{
tabBody.rows[rowIndex].cells[i].childNodes[0].disabled = true;
}
else
{
tabBody.rows[rowIndex].cells[i].childNodes[0].disabled = false;
}
}
}
}
}
}
function chgEdit(colIndex,tab)
{
var tabBody = tab.tBodies[0];
var oneRow;
if(tabBody.rows[1].cells[colIndex].childNodes[0].disabled)
{
for(var i=1;i<tabBody.rows.length-1;i++)
{
oneRow = tabBody.rows[i];
if(oneRow.cells[colIndex].childNodes[0].id.indexOf('LrcTb_') != -1)
{
oneRow.cells[colIndex].childNodes[0].disabled = false;
oneRow.cells[colIndex].childNodes[0].className = "lrc_txt_show";
}
else if(oneRow.cells[colIndex].childNodes[0].id.indexOf('LrcDrl_') != -1)
{
oneRow.cells[colIndex].childNodes[0].disabled = false;
}
}
}
else
{
for(var i=1;i<tabBody.rows.length-1;i++)
{
oneRow = tabBody.rows[i];
if(oneRow.cells[colIndex].childNodes[0].id.indexOf('LrcTb_') != -1)
{
oneRow.cells[colIndex].childNodes[0].disabled = true;
oneRow.cells[colIndex].childNodes[0].className = "lrc_txt_hid";
}
else if(oneRow.cells[colIndex].childNodes[0].id.indexOf('LrcDrl_') != -1)
{
oneRow.cells[colIndex].childNodes[0].disabled = true;
}
}
}
}
function BuildSql(tabName)
{
var UpdSql = '';
var tabBody = tabName.tBodies[0];
var oneRow;
var len = tabBody.rows.length;
var celLen = tabName.rows[0].cells.length;
var isadd = tabName.getAttribute("isadd");
var isdel = tabName.getAttribute("isdel");
if(isdel == 'True')
{
celLen = celLen -1;
}
var hidIndex = 0;
if(isadd == 'True')
{
hidIndex = 2;
}
var tabN = tabBody.rows[len-1].cells[hidIndex].childNodes[1].value;
var colN = tabBody.rows[len-1].cells[hidIndex].childNodes[2].value;
var colNA = colN.split(",");
var priK = tabBody.rows[len-1].cells[hidIndex].childNodes[3].value;
var priKA = priK.split(",");
var editCol = tabBody.rows[len-1].cells[hidIndex].childNodes[4].value;
var editColA;
if(editCol == 'LrcAllEdit')
{
var len = colNA.length - priKA.length;
editColA = new Array(len);
var indexE = 0;
for(var i = 0 ; i< colN