Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Velmurugan on Jun 04, 2009 21:29
open dhtmlx forum
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
<script>
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
Answer posted by Support on Jun 05, 2009 01:51
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();

Answer posted on Jun 05, 2009 02:26
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.
Answer posted by Support on Jun 05, 2009 03:49
>>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

Answer posted on Jun 05, 2009 05:36
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]+"<input type='checkbox' /> 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]+"<input type='checkbox' /> 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?

Answer posted by Support on Jun 05, 2009 06:37
>>After i have added tha above code, It should be

dhtmlXGridObject.prototype._in_header_master_checkbox=function(t,i,c){
     t.innerHTML=c[0]+"<input type='checkbox' /> 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;
     }  
}




Answer posted on Jun 09, 2009 06:32
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.
Answer posted by Alex (support) on Jun 09, 2009 07:00

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]+"<input type='checkbox' />"+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. 

Answer posted on Jun 09, 2009 21:02
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.
Attachments (1)
grid.png122.31 Kb
Answer posted by Alex (support) on Jun 10, 2009 01:59

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 http://dhtmlx.com/docs/products/kb/index.php?s=normal&q=9811&a=15843 answer).