getUserData() fetching improper data

Hi,



I am using dhtml xgrid, I trying to fetch global data using getUserData() method, I am getting empty data.



The below code I am using:



//set global user data

function setGlobalUserData(colNullable){



nullableColumns = colNullable.split(",");

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



mygrid.setUserData("",“column_”+i,nullableColumns[i]);

}



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

alert(mygrid.getUserData("",“column_”+i));

}



}



In the above code in second for loop I am able to see the global data using getUserData() function.

I am able to see the data in alert messages.



But later I am editing some rows and calling a method after clicking SAVE button:



Here the code follows:



//save the grid values using Data Processor

function saveGridData(){



for (var i=0; i<5; i++){

alert(mygrid.getUserData("",“column_”+i));

}



alert(“Changed Rows------>”+mygrid.getChangedRows());

var ids = mygrid.getChangedRows().split(",")

for (var i=0; i<ids.length; i++)

for (var j=0; j<mygrid.getColumnsNum(); j++){



alert(mygrid.getUserData("",“column_”+j));

if(mygrid.getUserData("",“column_”+j) == ‘N’ && (mygrid.cells(ids[i],j).getValue() == null || mygrid.cells(ids[i],j).getValue() == “”)){

var columnId = mygrid.getColumnId(j);

document.getElementById(“divErrors”).innerHTML = "A value is required for column "+columnId;

return false;

}



}



}



In the above code I am getting global data as empty in alert messages. In all alert messages the data is empty.



Can u please help me to solve the above problem?





/Thanks

Raj


In which moment setGlobalUserData function called?



If it was called before grid was initialized - the old userdata may be lost. Each time when grid (re)initialized - old userdata values erased ( after grid.init() or after loading configuration from XML )


Hi,



First I was called before grid initialized, but after seeing your answer I called the setGlobalUserData () method after grid initialized, But I am getting the same result…



Actually I am getting the grid initialization(setting the headers and levels,etc) code before loading the grid and calling grid.load() function.



So I am setting the global data at before loading the grid. Please see my code let me know the cause for issue…



Code:



// The heade and other values I am fetching dynamically



header=header+pcontArray[0];
            levelHeader=levelHeader+pcontArray[1];
            param1=param1+pcontArray[2];
            param2=param2+pcontArray[3];
            columnIds = columnIds + pcontArray[4];
            intiWidths = pcontArray[5];
            colTypes = pcontArray[6];
            colSorting = pcontArray[7];
            colNullable = pcontArray[8];



if(typeof(mygrid) == “undefined”){
            mygrid = new dhtmlXGridObject(‘gridbox’);
            mygrid.setHeader(levelHeader);
            mygrid.attachHeader(header);
            mygrid.setColumnIds(columnIds); // here the ID’s of columns need to be set
            mygrid.setInitWidths(intiWidths);
            mygrid.setColTypes(colTypes);
            mygrid.setColSorting(colSorting);
            
            mygrid.setOnRowSelectHandler(doOnRowSelected);
           
            mygrid.setImagePath(“images/Imgs/”);
            mygrid.enableBuffering(30);
            mygrid.setEditable(mygrid.isEditable);
            mygrid.setSkin(“xp”);
            mygrid.setDateFormat(“d.m.y”); 
            mygrid.init();
            setGlobalUserData(colNullable);
            mygrid.attachEvent(“onGridReconstructed”,function(){
            mygrid._fake.resetCounter(0)   // reset cntr indexes for column with index == 0
            return true;
            })
            //function called when editing of a cell
            mygrid.attachEvent(“onEditCell”,function(stage,id,ind,value){
                if (stage==2) {
                    var type = mygrid.fldSort[ind];
                    var columnId = mygrid.getColumnId(ind);
                   
                        if (!some_check(value,type,columnId)) {
                            alert(“incorrect data”);
                            return false;
                        }
                }
            return true;
            })
            mygrid.splitAt(1); 
            mygrid.enableAutoHeight(true,270);
           
            mygrid.clearAll();
            mygrid.loadXML(‘fetchDetails.do?methodName=loadGrid&param1=’+param1+’&param2=’+param2);
           
            //============================================================================================
   
    myDataProcessor = new dataProcessor(‘fetchDetails.do?methodName=loadGrid&param1=’+param1+’&param2=’+param2);
    myDataProcessor.enableDebug(true);
    myDataProcessor.enableDataNames(true);
   
    myDataProcessor.setUpdateMode(“off”);//available values: cell (default), row, off
    myDataProcessor.defineAction(“error”,myErrorHandler);
    myDataProcessor.defineAction(“insert”,setUserDataFunction);
      myDataProcessor.defineAction(“delete”,setDleteFunction);
      myDataProcessor.defineAction(“update”,setUserDataFunction);
    myDataProcessor.setTransactionMode(“GET”,true);
    myDataProcessor.init(mygrid);




}



Please help me this regard and let me know I am doing any thing wrong…



/Raj



 


The code is correct , and must not cause any issues



Please check sample, which was sent to your email, it uses similar approach in grid iniitialization and all works correctly.