how to send extra values to server side using dataprocessor?

Hi,

I am using Grid with subgrid for handling records and using dataprocessor to save data into database. Now my problem is i collecting checked row ids from the subgrid, and i want send those IDs into server side using data processor. how to do that?

here is my code



var customerID=document.getElementById(‘customerID’).value;

var xmlfile=document.getElementById(‘xmlFile’).value;

var xmlFile=“GridXML/”+xmlfile;



    mygrid = new dhtmlXGridObject(‘gridbox’);

    mygrid.setImagePath(“themes/General/css/images_dhtmlgrid/”);

mygrid.setHeader(" ,IP Address,Sys Name,Interface Count,Assign Impact");

    mygrid.setColumnIds(“collapse,ip,name,interface_count,impact”);

    mygrid.setInitWidths(“30,255,255,255,255”)

    mygrid.setColAlign(“left,left,left,left,left”)

    mygrid.setColTypes(“sub_row,ro,edtxt,ro,co”);

    

    mygrid.getCombo(4).put(‘Low’,“Low”);

mygrid.getCombo(4).put(‘Medium’,“Medium”);

mygrid.getCombo(4).put(‘High’,“High”);



mygrid.init();



mygrid.attachEvent(“onBeforePageChanged”,function(){

             if (!this.getRowsNum())

                 return false;

             return true;

         })



mygrid.enablePaging(true,3,10,“pagingArea”,true,“infoArea”);

mygrid.setPagingSkin(“bricks”);

    mygrid.loadXML(xmlFile);

    

    mygrid.objBox.style.overflowX=“hidden”;

    var url="?page=ViewManageEdit&customerID="+customerID+"&mode=updateViewmanage";

    //alert(url);

    myDataProcessor = new dataProcessor(url);

    myDataProcessor.enableDataNames(true);

    myDataProcessor.setUpdateMode(“off”);//available values: cell (default), row, off

    myDataProcessor.setTransactionMode(“POST”);

    myDataProcessor.init(mygrid);

            

    mygrid.attachEvent(“onSubGridCreated”,function(subgrid,id,index){

//will be called , each time when subgrid created

var dp = new dataProcessor(url); // create new instance

dp.init(subgrid); // attach it to subgrid

return true;

})



function CollectCheckedRows()

{

gridIDs=mygrid.getAllRowIds(",");

// alert(gridIDs);

var temp = new Array();

temp = gridIDs.split(’,’);



var myarr=new Array();

var arrLen=temp.length;

//alert(arrLen);



for(var i=0; i<arrLen; i++ )

{

var sub=mygrid.cells(temp[i],0).getSubGrid();

var Ids=sub.getCheckedRows(0);

if(Ids!=“None”)

{

myarr.push(Ids);

}

}

if((myarr.length) > 0)

{

var TotalIds=myarr.join(",");

return TotalIds;

}

else

{

return “None”;

}

}



function save()

{

IDs=CollectCheckedRows();

document.getElementById(“checkedIDs”).setAttribute(“Value”,IDs);

document.getElementById(“mode”).setAttribute(“Value”,“updateviewmanage”);

myDataProcessor.sendData();



}



Here, the function save() is called when i click the save button. i want to get IDs=CollectCheckedRows(); values in the server side? how do i do that? It is better if i send those values thru URL using GET Method?Is it Possible?

Please help me.



Thanks,

Vel

You can store such info in global userdata , all userdata related to row ( and global userdata ) sent to server with each dataprocessor’s call


function save()
{
IDs=CollectCheckedRows();
document.getElementById(“checkedIDs”).setAttribute(“Value”,IDs);
document.getElementById(“mode”).setAttribute(“Value”,“updateviewmanage”);
mygrid.setUserData(“checked”,IDs); //you will have POST[“checked”] on server side
myDataProcessor.sendData();
}

Hi,
Thanks for the reply. Actually i am using #master_checkbox concept for manage a checkbox column.
When i click the checkbox which avalilabe in every row of a subgrid, the row has changed into “bold” highlighted And i can get those values in server side.But when I check checkboxs using master check box, the rows color is not changed or highlighted and I cant able to get the values in server side. what is the problem? how do i handle this situation? i want get all the checked row ids.

and I cant able to get the values in server side. what is the problem?
By default dataprocessor catches only edit actions, which are result of direct user actions. When state of cell changed programmatically - it doesn’t trigger dataprocessor’s actions.

To change behavior, you can update code of master checkbox ( or create custom control with similar functionality )

dhtmlxgrid_filter.js

dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){

self.forEachRow(function(id){
var c=this.cells(id,j);
if (c.isCheckbox()) c.setValue(val);
dp.setUpdated(id,true); //this line can be added - marks row as updated

Hi,
Thanks for ur help. Can u explain where do i put the above code you sent. In my  dhtmlxgrid_filter.js, the existing code is

dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){
    t.innerHTML=c[0]+" Manage"+c[1];
    var self=this;
    t.firstChild.onclick=function(e){
        self._build_m_order();
        var j=self._m_order?self._m_order[i]:i;
        var val=this.checked?1:0;
        for (var k=0; k<self.getRowsNum(); k++){
            var c=self.cells(self.getRowId(k),j);
            if (c.isCheckbox()) c.setValue(val);
        };
        (e||event).cancelBubble=true;
    }  
   }

After i have added tha above code, It should be

dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){
    t.innerHTML=c[0]+" Manage"+c[1];
    var self=this;
    t.firstChild.onclick=function(e){
        self._build_m_order();
        var j=self._m_order?self._m_order[i]:i;
        var val=this.checked?1:0;
        for (var k=0; k<self.getRowsNum(); k++){
            var c=self.cells(self.getRowId(k),j);
            if (c.isCheckbox()) c.setValue(val);
        };
        (e||event).cancelBubble=true;
    }  
    self.forEachRow(function(id){
           var c=this.cells(id,j);
           if (c.isCheckbox()) c.setValue(val);
           myDataProcessor.setUpdated(id,true);
           }
}
But now also the rows are not updated. and i am not getting checked rows values in server side?
Is it the correct way the code implemented?
Please help me. How to do that?

After i have added tha above code, It should be

dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){
t.innerHTML=c[0]+" Manage"+c[1];
var self=this;
t.firstChild.onclick=function(e){
self._build_m_order();
var j=self._m_order?self._m_order[i]:i;
var val=this.checked?1:0;
for (var k=0; k<self.getRowsNum(); k++){
var c=self.cells(self.getRowId(k),j);
if (c.isCheckbox()) c.setValue(val);
myDataProcessor.setUpdated(self.getRowId(k),true);
};
(e||event).cancelBubble=true;
}
}



Hi,
Thanks for help. still i am not getting checked values in server side?
i am getting only updated rows from the grid and subgrids using dataprocessor. I think myDataProcessor.setUpdated(self.getRowId(k),true); is not taking effect. Actually i am using #master_checkbox is in subgrids only. Please help me. Thanks.


Hello,


in case of subgrids’ master_checkbox this issue becomes much more complicated as DataProcessor is defined for the parent grid (so you setUpdate for this grid, not for subgrid).


The possible solution is:


1) to set onSubGridCreated event handler that will define property for sub grid that is equal to parent grid id:


parentgrid.attachEvent(“onSubGridCreated”,function(subgrid,id){


subgrid.parent_row_id = id;





return true


})


2) then you should modify dhtmlxgrid_filter.js as follows:


dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){
t.innerHTML=c[0]+""+c[1];
var self=this;
t.firstChild.onclick=function(e){
self._build_m_order();
var j=self._m_order?self._m_order[i]:i;
var val=this.checked?1:0;
if(self.parent_row_id){
parentgrid.setUserData(self.parent_row_id,“ch_state”,val);
myDataProcessor.setUpdated(self.parent_row_id,true)
}

self.forEachRow(function(id){
var c=this.cells(id,j);
if (c.isCheckbox()) c.setValue(val);
});
(e||event).cancelBubble=true;
}
}







In this case the for the row will be sent userdata with checkbox state.

hi,
thanks for your help. Still i am not getting the solution.
herewith i have attached screenshot which describe about my exact requirements. I want get edited rows values from grid and subgrid and check box values from subgrid. Those checkboxs are checked/unchecked using master checkbox. Please find the attached screenshot and send a sample sode that should satisfy my needs. Expecting your mail. Thanks.



Hello,


so, the checkbox state is sent to the server, but other subrows data aren’t. Am I right ?


The simplest solution is to define own Data Processor for each sub grid. In this case the changed subgrid data will be also sent to the server (the master_checkbox should be modified as recommended in the dhtmlx.com/docs/products/kb/inde … 11&a=15843 answer).