lvalverdeb
Posts: 299
|
| Posted: 02/16/2005, 7:23 AM |
|
I used to get that same error but can't remember the reason why . Anyhow, since I use that functionality quite a bit, I wrote the following functions which fixed the "Undefined offset" error and made it easier to implement it as well.
function HideEmptyRows(&$Form,$CurrRow) {
$Form->RowIDAttribute->SetValue($CurrRow);
//Configure the row's properties based on its state (empty or filled)
if (($CurrRow <= $Form->PageSize) && ($CurrRow <= $Form->ds->RecordsCount)) {
$Form->RowNameAttribute->SetValue("FillRow");
} else {
$Form->RowNameAttribute->SetValue("EmptyRow");
$Form->RowStyleAttribute->SetValue("style=\"display:none;\"");
if ($CurrRow <= $Form->TotalRows)
{
if (isset($Form->RowErrors[$CurrRow]))
{
if($Form->RowsErrors[$CurrRow]) {
$Form->RowStyleAttribute->SetValue("");
}
}
}
}
return $Form;
}
In order to use it you have to:
1) "include" it in your Common.php
2) Just like in the example define a global $RowNumber with the initial value set to zero.
3) Call the call it from the grid's BeforeShowRow event like this:
$RowNumber++;
HideEmptyRows($YourGridObjectGoesHere,$RowNumber);
4) Also, I "cloned" the Javascript function in the example and made it generic to handle the "Add New" functionality. The code is as follows:
function AddRow(myForm)
{
var result;
var NS6 = (!document.all && document.getElementById) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var FormState = myForm.FormState.value.split(";");
var AllLength = parseInt(FormState[0])+parseInt(FormState[1]);
if (parseInt(FormState[0]) == 0 ) {
FormState[0] = 1;
}
var i;
for (i=FormState[0]; i<AllLength; i++) {
var objRow = document.getElementById(i);
if (NS6) {
if (objRow.style.display == "none") {
objRow.style.display = '';
result = i;
break;
}
} else {
if (objRow.style.display == "none") {
objRow.style.display = "block";
result = i;
break;
}
}
}
if (i >= AllLength)
myForm.AddRowBtn.disabled = true;
return result;
}
5) The AddRow function you have to call it from the Client On-Click Event and pass as parameter the grid's form name. For example:
result = AddRow(document.forms["yourformnamegoeshere"]);
the only catch in the JS function is that your "Add New Button" must be called AddRowBtn.
6) You need to follow the other steps in the tutorial with regards to the manual HTML tags, etc.
Hope this helps
Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4 |