web| Script | control | style sheet full edit WebGrid control Lrcgrid (4)--script library and style sheet
Script Library: A function that contains a control client action. Including:
function to switch table rows to edit mode: Chgeditrow (Rowindex,tab) ()
function to switch table columns to edit mode: Chgedit (Colindex,tab)
To construct an SQL statement that updates a database on a client: BuildSQL (tabname)
Functions to add new records: addrow (tab)
Remove the newly added row function: removerow (tab)
All JS code:
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< colna.length; i++)
{
var ispri = 0;
for (Var j=0;j<prika.length;j++)
{
if (prika[j] = = i)
{
Ispri = 1;
}
}
if (ispri = 0)
{
Editcola[indexe] = i;
indexe++;
}
}
}
Else
{
Editcola = Editcol.split (",");
}
var strupd = "UPDATE" + tabn + "SET";
var strins = "INSERT" + Tabn + "(" + Coln + ") VALUES (";
for (Var i=1;i<tabbody.rows.length-1