Master CheckBox check/uncheck event

i have a column with master checkbox on header and checkboxes below. When i click the master checkbox i want to run an on check event for all the checked boxes. The idea is to check the state of the master box and if it is checked to run a code and if it is unchecked to run some other code. i tried the oncheck event and the oncheckbox event but nothing happens. checking individually each checkbox works. Any help?

I apologize for the delay.
You may use the onCheckbox event:
https://docs.dhtmlx.com/api__dhtmlxgrid_oncheckbox_event.html

As i said it doesnt work for all. Only for each checkbox individually. Do i miss something?

 myGrid.attachEvent("onCheckbox", function (rId, cInd, state) {
    if (state === true) {
        if (myGrid.cells(rId, 8).isChecked()) {
            if ((myGrid.cells(rId, 6).getValue() !== "")) {
                amount3 = +amount3 + +myGrid.cells(rId, 6).getValue();
                text2 = +text2 + 1;
                subLabel2 = +subLabel2 + +myGrid.cells(rId, 6).getValue();
                if (amount3 === 0) {

                    //do something
                } else {

                   //do something
                }
            } else if ((myGrid.cells(rId, 7).getValue() !== "")) {
                amount3 = +amount3 - +myGrid.cells(rId, 7).getValue();
                text3 = +text3 + 1;
                subLabel3 = +subLabel3 + +myGrid.cells(rId, 7).getValue();
                if (amount3 === 0) {
                   ///do something
                } else {

                   ///do something
                }

            }

        }

    } else if (state === false) {
        if (myGrid.cells(rId, 8).isChecked() === false) {
            if ((myGrid.cells(rId, 6).getValue() !== "")) {
                amount3 = +amount3 - +myGrid.cells(rId, 6).getValue();
                text2 = +text2 - 1;
                subLabel2 = +subLabel2 - +myGrid.cells(rId, 6).getValue();
                if (amount3 === 0) {
                   //do something
                } else {
					//do something
                }
            } else if ((myGrid.cells(rId, 7).getValue() !== "")) {
                amount3 = +amount3 + +myGrid.cells(rId, 7).getValue();
                text3 = +text3 - 1;
                subLabel3 = +subLabel3 - +myGrid.cells(rId, 7).getValue();
                if (amount3 === 0) {
                    
                   //do something
                } else {
					//do something
                }


            }
        }

    }

Nevermind, I found it
I used this to check if master checkbox is checked or not

var checked = myGrid.hdr.rows[1].cells[8].getElementsByTagName(“INPUT”)[0].checked;

thanks!