Subgrid -> Connector -> strange loading issue

Hi!

I’ve got another Problem and i can’t figure out why it doesn’t work! Could you please help me?

I have a main grid, which loads distinct database entries. It groups the MySQL results so the main grid is populated with a minimum of rows. In the first cell of each row should be a (+) sign. When expanding / creating a new sub grid it should load XML data created with Connector. This works, i pass variables via URL (they are preserved, this works nice.) but blocking the default behavior via the events onSubGridCreated and onSubGridLoaded doesn’t work.

For example this is the code:

mygrid = new dhtmlXGridObject("gridbox");

mygrid.setImagePath("dhtmlxGrid/codebase/imgs/");
mygrid.setHeader("POS,Krz,ProjNr,Name,Datum,Lieferant,Art.Krz,ArtBeschr,Beschr,Menge,Einheit,E-Preis OK,E-Preis,Rabatt %,LSVA %,LSVA Fr,P total exkl MwSt,Kontakt,T exkl MwSt,Total inkl MwSt,Rechnung OK,Rechnungsdatum,Wir-Anteil Fr.,Wir-Anteil %,Lieferdatum,Lieferort,Wer braucht,Ort");
mygrid.attachHeader(" , , ,#select_filter,#select_filter,#text_search,#select_filter,#select_filter,#text_search,#text_search, ,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,#text_search,,#cspan,#cspan,#cspan,#cspan,#cspan,#cspan,#text_search,#text_search, ,#text_search");
mygrid.setColAlign("center,center,center,left,left,center,left,left,left,left,center,center,center,center,center,center,center");
mygrid.setColTypes("sub_row_grid,ro,ed,edtxt,txt,edtxt,txt,edtxt,edtxt,txt,ed,ed,edn,edn,ed,ed,ed,ron,ed,edn,ron,edn,ed,edn,ed,ed,txt,txt,txt");
mygrid.setNumberFormat("0,000.00",11,".","\'");
mygrid.setNumberFormat("0,000.00",12,".","\'");
mygrid.setNumberFormat("0,000.00",16,".","\'");
mygrid.setNumberFormat("0,000.00",18,".","\'");
mygrid.setNumberFormat("0,000.00",19,".","\'");
mygrid.setNumberFormat("0,000.00",20,".","\'");
mygrid.setNumberFormat("0,000.00",22,".","\'");
mygrid.setColSorting("int,str,int,str,str,str,str,str,str,int,str,int,int,int,int,int,int,str,int,int,int,str,int,int,str,str,str,str");
mygrid.setSkin("dhx_blue");
mygrid.init();
mygrid.load(\'./php/get_control_distinct.php\');

this works… the events:

mygrid.attachEvent("onSubGridCreated",function(subgrid, id, ind){

var connectorURL = "php/get_control.php?project=" + mygrid.cells(id,2).getValue() + "&date=" + mygrid.cells(id,4).getValue();

subgrid.setHeader("POS,Krz,ProjNr,Name,Datum,Lieferant,Art.Krz,ArtBeschr,Beschr,Menge,Einheit,E-Preis OK,E-Preis,Rabatt %,LSVA %,LSVA Fr,P total exkl MwSt,Kontakt,T exkl MwSt,Total inkl MwSt,Rechnung OK,Rechnungsdatum,Wir-Anteil Fr.,Wir-Anteil %,Lieferdatum,Lieferort,Wer braucht,Ort");

subgrid.init();
subgrid.load(connectorURL);

return false; // block the default subgrid logic
      
});

… this gives me a + sign in the main grid, but it won’t expand a sub grid. I tried it in every way, it’s not the & which causes incorrect XML and the like, it doesn’t event work with hard-coded connector XML-results. I included every JS library which is needed:

[code]

[/code]

This is very strange as before anything is done in the sub grid, it’s configured and the data is loaded. I tried it with both events, configuring and initiating the grid with true return-value in “created” event and with false return-value in “loaded” event. But the onSubGridLoaded event doesn’t fire when subgrid.init(); is called.

When i place it in the onSubGridLoaded Event, the configuration, initialization and loading, it works but then it gives me an incorrect XML error.

This is get_control.

header('content-type: text/xml; charset=utf-8');
require("../dhtmlxConnector/codebase/grid_connector.php");
$res = mysql_connect('comput1.mysql.db.internal', '', '');
@mysql_select_db('comput1_grid');
@mysql_set_charset('utf8', $res);
$gridConn = new GridConnector($res,"MySQL");
$gridConn->dynamic_loading(100);

$zeroValueFields = array('newprbool', 'newpr', 'discount', 'lsvaperc', 'lsvafr', 'totalnotax', 'billbool', 'weamfr', 'weamperc');

$gridConn->event->attach("beforeRender",removeZeros);
$gridConn->event->attach("beforeProcessing",calc_total);

function removeZeros($data)
{
	    
	    global $zeroValueFields;
	    
	    foreach ($zeroValueFields as $arrVal)
	    {
			if ($data->get_value($arrVal) == 0)
				    {
						$data->set_value($arrVal, '');
				    }
		  }

}

function calc_total($data)
{
	

            $pretotal = (float)$data->get_value("quant") * (float)$data->get_value("newpr");
	    
	    $totalwithtax = (float)$data->get_value("totalnotax") + (((float)$data->get_value("totalnotax") / 100) * 8);
	    
            $discount = ($pretotal / 100) * (float)$data->get_value("discount");
            
            $lsvaperc = ($pretotal / 100) * (float)$data->get_value("lsvaperc");
            
            $lsvafr = (float)$data->get_value("lsvafr");
            
            if ($lsvaperc !== 0 AND $lsvafr == 0) { $total = ($pretotal-$discount)+$lsvaperc; }
            elseif ($lsvafr !== 0 AND $lsvaperc == 0) { $total = ($pretotal-$discount)+$lsvafr; }
            else { $total = (($pretotal-$discount)+$lsvafr)+$lsvaperc; }
	    
            $data->set_value('totalwithtax', $totalwithtax);
            $data->set_value('ptotalnotax', $total);
            $data->remove_field('pos'); // otherwise auto_increment doesnt work for 'pos'
}

	    $gridConn->render_sql("SELECT * FROM `aktuell` WHERE `projnr` = $_GET['project'] AND `date` = $_GET['date']", "pos", "pos,shrt,projnr,name,date,distrib,artshrt,artdesc,descr,quant,unit,newprbool,newpr,discount,lsvaperc,lsvafr,ptotalnotax,contact,totalnotax,totalwithtax,billbool,billdate,weamfr,weamperc,deliveryd,deliverypl,whoneeds,place");

?>

Do you have an idea which could help me? Is it the Identifier-Field which is used as the sub_row_grid? But that shouldn’t break it, because default logic is blocked anyhow in the SubGrid event :slight_smile:

Help would be very appreciated :slight_smile: thanks in advance :smiley: !!!

Greetings Nick !

Update,

It actually works fine with firefox and ie, but on safari nothing shows up when trying to open the sub grid with a click. Safari Version 5.1 (7534.48.3) on Mac OSX.

Greetings

The code looks mostly correct, there is no any visible issues which can cause the described behavior.

If issue still occur can you provide some kind of demo link ,where problem can be checked?

Hello Stanislav,

I tried this several times, it seems to be some kind of javascript incompatibility with Safari on Mac OSX. It seems that nothing is loaded or rendered inside the browser when trying to click/expand a (+) symbol to a sub grid.

However this is only happening on Grid with sub grid feature. I found an easier solution with TreeGrid and it works very very good. Everything is opened/expanded loaded on every browser i have.

If you are still interested in a demo i can provide you the URL to the test grid, where error occurs.

Greetings and thanks for the reply!

Nick