Validar valores duplicados en las filas con JavaScript de un control UltraWebGrid de Infragistics

Código JavaScript que valida que no se repitan valores duplicados en un control UltrawebGrid de infragistics. 

function ValidarDuplicadosColumnaGrid(col)

 

    var oGrid = ouwgDatos;

    var oRows = oGrid.Rows;

    delete oGrid;

    

    if (oRows.length == 0 )

    {

     delete oRows;

     return 0;

    }

    

    var rowObj;

    var cellvalue1 = " ", cellvalue2 = " ";

    var err = 0;

    var i, j;

    

    for(i=0; i<oRows.length; i++) {

        rowObj=oRows.getRow(i);

        //obtener el valor de la columna del ultrawebGrid por filas

        cellvalue1 = rowObj.getCellFromKey(col).getValue();         

        if(err != 0)

         break;        

     //vuelve a recorrer todas las filas para verificar

     //que no exista el valor de columna repetido en la fila actual "valor de i"    

        for(j=i+1; j<oRows.length; j++) {

            rowObj=oRows.getRow(j);

            cellvalue2 = rowObj.getCellFromKey(col).getValue();

            if(cellvalue1 != null && cellvalue2!=null && cellvalue1 != 0 && cellvalue2 != 0 )

            {

             //compara el valor para que no se repita

             //en este caso valido una columna de tipo númerico

             if(typeof(cellvalue1)=="number")

             {

             if(trim(cellvalue1) == trim(cellvalue2))

             {

                 err++;

                 break;

             }

             }

             //comparación para datos tipo string

             else

             {

             if(trim(" "+ cellvalue1).toUpperCase() == trim(" " + cellvalue2).toUpperCase())

             {

                 err++;

                 break;

             }

             }

            }

        }

        delete cellvalue1;

        delete cellvalue2;

        delete rowObj;

    }

    

    delete oRows;

    return (err);

}

About omaracostacasas

ING SOFTWARE
This entry was posted in Infragistics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s