From_time index is 1 and To_time index is 2
hi
In the above code, ‘i’ is row no and not row id but it works for grid.cells(i,index).getvalue();
In the conditional loop, i.e. in if(end_time>from_time), i actually got to change the cell background color, which i thought of achieving using setCellTextStyle(rowid,index,“background-color:white;”) function, but was struck as i am unsure if the function works with row no instead of rowid as its parameter, can you please confirm if this works or provide me an alternative to achieve the same.
Hi stanislav,
i have checked the overlapping of time as
function compare_row_time()
{
var status_flag =false;
for (var i=1; i<grid.getRowsNum(); i++)
{
var tt_row=grid.cells(i-1,2).getvalue();
var ft_row=grid.cells(i,1).getvalue();
var tt_split=tt_row.split(":");
var ft_split=ft_row.split(":");
if (tt_split[0] > ft_split[0])
{
alert('true condition');
// grid.setCellTextStyle(i,1,"background-color:white;");
}
else if((ft_split[0]*1 == tt_split[0]*1) && (ft_split[1]*1 > tt_split[1]*1))
{
alert('true condition');
// grid.setCellTextStyle(i,1,"background-color:white;");
}
else
{
alert('condition failed');
// grid.setCellTextStyle(i,1,"background-color:yellow;");
status_flag = true;
}
}
return status_flag;
}
//onclick event:
function save()
{
if(!compare_row_time())
{
myDataProcessor.sendData();
}
if(err_str!="")
jAlert('info',err_str,'Error Message');
err_str="";
$("#result").html(" ");
}
im getting error as ‘_childIndexes’ is NULL or not an object.
any idea!
hi
when i used
for(var i=1;i<mygrid.getRowsNum().length;i++)
im not getting the error but actuall im unable to alert the tt_row and ft_row values.
the loop is not working.
how should i do this looping?
for (var i=1;i<grid.getRowsNum().length;i++)//gives undefined.
im getting error as ‘_childIndexes’ is NULL or not an object.
this is result of incorrect row id usage in some API call
In your code you are using row indexes as rows ids ( using of “i” in commands ) , instead of it you may try to obtain row id as
var id = grid.getRowId(i);
and use id instead of i for setCellTextStyle and cells commands
for(var i=1;i<mygrid.getRowsNum().length;i++)
valid syntax is
for(var i=0;i<mygrid.getRowsNum();i++)
Hi stanislav,
function compare_row_time()
{
var status_flag=false;
for(var i=1;i<mygrid.getRowsNum();i++)//CHECKING FROM 2ND ROW
{
var tt_row=mygrid.cells2(i-1,2).getValue();//i=1-1=0,CELL INDEX-2(TO-TIME)
var ft_row=mygrid.cells2(i,1).getValue();//i=1,CELL INDEX-1(FROM-TIME)
var tt_split=tt_row.split(":");
var ft_split=ft_row.split(":");
var id_samp=mygrid.getRowId(i);
var val0=mygrid.cells2(i,0).getValue();//used of messages
var val1=mygrid.cells2(i-1,0).getValue();//used of messages
if(ft_split[0]*1 > tt_split[0]*1)
{
mygrid.setCellTextStyle(id_samp,1,"background-color:white;");
}
else if((ft_split[0]*1 == tt_split[0]*1) && (ft_split[1]*1 > tt_split[1]*1))
{
mygrid.setCellTextStyle(id_samp,1,"background-color:white;");
}
else if(ft_row!="")
{
mygrid.setCellTextStyle(id_samp,1,"background-color:#FFFF99;");
if(err_str!="")
err_str+="\n"+(i+1)+"."+val0+" FROM-TIME SHOULD BE GREATER THAN "+val1+" TO-TIME VALUE.";
else
err_str=(i+1)+"."+val0+" FROM-TIME SHOULD BE GREATER THAN "+val1+" TO-TIME VALUE.";
status_flag = true;
}
}
return status_flag;
}
here when i click the button if a cell is invalid im highlighting it and alerting it,when im clicking on the button for first time its showing alert but not highlighting,the second time when i click its showing.
hi
The function compare_row_time() only works if it is in Sequence order,but if i change the sequence this function is not working bco’z row_Id is not in sequence.
for ex:
in example:1; here type has typename which contains type_id i.e, row_Id
the type is in sequence format
say
f1=1
f2=2
f3=3
f4=4
when i checked example-1 its working fine
example:1
type start-time end-time
f1 5:00 6:00
f2 7:00 8:00
f3 9:00 10:00
f4 11:00 12:00
Success Condition
but if when the sequence is changed as
Example-2:
type start-time end-time
f3 9:00 10:00
f1 5:00 6:00
f4 11:00 12:00
f2 7:00 8:00
here sequence order is 3,1,4,2
in example-2 if I a add new type that can be placed any where so, in this comparing time overlapping will fail.
the time once given shouldnot overlap in any other row.
any
Regards
narinas.
It is not compulsory that next row start time should start with previous row end time.
give me some idea on this.
thank you.
Do you have some live sample where it can be reconstructed?
function compare_row_time()
{
var status_flag=false;
for(var i=1;i<mygrid.getRowsNum();i++)//CHECKING FROM 2ND ROW
{
var tt_row=mygrid.cells2(i-1,2).getValue();//i=1-1=0,CELL INDEX-2(TO-TIME)
var ft_row=mygrid.cells2(i,1).getValue();//i=1,CELL INDEX-1(FROM-TIME)
var tt_split=tt_row.split(":");
var ft_split=ft_row.split(":");
var id_samp=mygrid.getRowId(i);
if(ft_split[0]*1 > tt_split[0]*1)
{
mygrid.setCellTextStyle(id_samp,1,"background-color:white;");
}
else if((ft_split[0]*1 == tt_split[0]*1) && (ft_split[1]*1 > tt_split[1]*1))
{
mygrid.setCellTextStyle(id_samp,1,"background-color:white;");
}
else if(ft_row!="")
{
mygrid.setCellTextStyle(id_samp,1,"background-color:#FFFF99;");
if(err_str!="")
err_str+="\n"+(i+1)+".TIME SHOULD NOT OVERLAP.";
else
err_str=(i+1)+".TIME SHOULD NOT OVERLAP.";
status_flag = true;
}
}
return status_flag;
}
//BUTTONS:
function save()
{
if(!compare_row_time())
{
myDataProcessor.sendData();
}
if(err_str!="")
jAlert('info',err_str,'Error Message');
err_str="";
$("#result").html(" ");
}
Actually now the problem is all the row id’s r in sequence accoring to the provided example(comparing overlaping of time is working fine) but when i change the sequence of it this code is not woking.
in that code i checked totime of one row with fromtime of next row.
Hello stanislav,
I have checked the overlapping of time by taking the values into an array and sorting them.
here im unable to insert data into cells when the cells are empty!
my code:
function compare_row_time()
{
var all_times= new Array();
var flag_check=false;
var count_times=0;
for(var i=0;i<mygrid.getRowsNum();i++)
{
var time_1=mygrid.cells2(i,1).getValue();//starttime value of i
var time_2=mygrid.cells2(i,2).getValue();//endtime value of i
all_times[count_times]=time_1;
count_times++;
all_times[count_times]=time_2;
count_times++;
}
var sort_times= new Array();
sort_times=all_times.sort();
for(var j=0; j<sort_times.length;j++)
{
if(sort_times[j]==sort_times[j+1])
{
flag_check=true;//if false data is inserted even it is wrong.
}
}
return flag_check;
}
function save()
{
if(!compare_row_time())
{
myDataProcessor.sendData();
}
if(err_str!="")
alert(err_str);
err_str="";
$("#result").html(" ");
}
1.Here in sort_times array if any duplicate values are present it will show error(this is only working when im checking with existing data in grid)
2.If im inserting new values into empty rows im not able to send data(if i change flag_check to false in [sort_times array]im able to insert values but if i give duplicate values also the data is getting inserted.this condition is false)
3.My pattern for time is user can enter time as 05:00 or 5:00 (if one row is having 5:00 & another row is having 05:00 it is not comparing; if the pattern is of same type it is checking for duplicates)
4.How can i highlight the duplicates cells & provide a message for it.
could u please reconstruct the above code without these errors.
thank you.
Regards
Narina