changing master checkbox behavior without modifying dhtmlxg

Hi,



I would like to change master checkbox behavior. I have seen other posts that suggest modifications to dhtmlxgrid_filter.js I want to try an alternative way because I am using this file on many pages and only one requires a different behavior. I am trying to do this using jquery as follows:





$(“div.hdrcell”).find(“input[type=checkbox]”).unbind(“click”).click(

        function(){

alert(“do nothing”);

}

);



my alert(“do nothing”) does get triggered in ADDITION rather then INSTEAD of the old behavior. Any idea what I should try ?



thanks!!!



Victoria

Instead of changing existing one, you can create a custom one

Add the next code to the page or separate js file

dhtmlXGridObject.prototype.in_headermy_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;
self.forEachRowA(function(id){
var c=this.cells(id,j);
if (c.isCheckbox()) c.setValue(val);
});
(e||event).cancelBubble=true;
}
}

Now you can use #my_checkbox in grid’s header
Of course, you can change above code in any necessary way.

This is great! Thank you so much!

Victoria

Hi,

I’m using dhtmlx grid on a Ruby on Rails project.

I have a checkbox in each line, attached to this function:

function doOnCheckBoxSelected(rID, cInd, state)
{
if (state==‘1’)
{
grid.cells(rID, 11).setValue(“Aprovado”);
var now = new Date();
now.format(“yyyy/mm/dd”);
grid.cells(rID, 10).setValue(now);
dp.setUpdated(rID, true);
}
else if (state==‘0’)
{
grid.cells(rID, 11).setValue(“Aprovacao Pendente”);
grid.cells(rID, 10).setValue("");
dp.setUpdated(rID, true);
}

		}

I want to use a custom master checkbox to do the same function as the normal checkbox on each line, which updates a different cell depending on the value of the checkbox.

Is this feasible? How can I achieve this?

Thanks

You can use above code snippet, just replace the action payload with code necessary in your case

self.forEachRowA(function(id){ if (val){ self.cells(id, 11).setValue("Aprovado"); var now = new Date(); now.format("yyyy/mm/dd"); self.cells(id, 10).setValue(now); dp.setUpdated(id, true); } else { self.cells(id, 11).setValue("Aprovacao Pendente"); self.cells(id, 10).setValue(""); dp.setUpdated(id, true); } } );

I have applied the suggestion for #my_checkbox:

myGrid.setHeader("id,1,#my_checkbox,crop,…

I have included a js file with the suggested code.

In my header, instead of seeing a checkbox, I see “#my_checkbox”. What might be the problem? Thanks.

As sometimes happens, merely asking the question makes the light go on. I was running the code too early in the loading of my page. Once I fixed this, the solution works perfectly. Thanks!