Custom implementation of smart rendering on grid

I want to be able to implement smart rendering on the grid, but without the conventional way of getting xml responses , with new data,from the server.
I have a separate service API which can give me new to-be-loaded data. I want to know, if i can achieve smart rendering , by using this API and the event handlers of the dhtmlxGrid.

I understand the grid , provides “onXLS” and “onDynXLS” events. I can place my service API call in the handlers of these events, to get new data, and return false, to achieve smart rendering with my custom web service.

However, i find that the “onDynXLS” event is not thrown at all.
grid.enableSmartRendering(true, 50)
This call throws the event, “onXLS”. But even if I scroll the grid, i dont see the “onDynXLS” event being thrown. Isnt the onDynXLS event handler called with params (start, count) , as per the doc ?

Also,
does grid.parse(data, “jsarray”) load data incrementally into the grid. Because, i will be creating “jsarray” data, which then has to be loaded into the grid incrementally, after every scroll (call to onDynXLS handler). If not, how can i bulk-load data incrementally. I would prefer not to use addRow , for every jsarray row.

Please help.

The problem is , that you have not load command at all, and grid will not initiate dyn. loading because it don’t know uri for data requests.

You can add the next line

grid.xmlFileUrl = “dummy”;

as result grid will generate correct onDynXLS events ( dummy value will not be used for any other operations, if you will return false from onDynXLS )

does grid.parse(data, “jsarray”) load data incrementally into the grid
Nope, it will not works. But you can use

json_data.pos = 100; //position at which new data need to be added
grid.parse(json_data, “json”)

docs.dhtmlx.com/doku.php?id=dhtm … at_details

Thanks for the information !
Can i not use grid.loadXML(“dummy”) ;
and then return false, in onXLS and onDynXLS event handlers ?

Actually, i have tried this, but i get an alert saying
"Error type: loadXML
Description: Incorrect XML " ,
inspite of my onXLS eventHandler returning false.

Can i not use grid.loadXML("dummy") ; and then return false, in onXLS and onDynXLS event handlers ?
Unfortunately it will not work. onDynXLS will not be executed for load command - so your blocking handler will not be used.

onXLS can be used for information only, it is not blockable.

So how do I get the initial load? For the initial load "onDynXLS " event is not triggered.

Why not use

grid.xmlFileUrl = "dummy"; grid.parse(my_initial_data, "json");

But even after the initial load ,“onDynXLS” is not being called for subsequent fetches of data.
Should the event be thrown after every scroll of the grid ?

How does the grid know the size of the scroller ? Is the total_count to be set somewhere ?

Sample is attached

Be sure to include dhtmlxgrid_json.js
1290087624.zip (103 KB)

Thank you for the file !
Surely clears a lot of things.

Is there a way to use grid.parse(data, “jsarray”);

If yes, how to set total_count and pos ?

Thanks.
Really appreciate your prompt help.

jsarray can’t store extra attributes , so it can’t be used to organize dynamic loading.

The JSON parsing is not working completely for me

I tried this :

[code]var jsonObj = new Object();
jsonObj.total_count = 100;
jsonObj.pos = 0;

jsonObj.rows = [];
var r = new Object(); r.data = ["a", "b"]; jsonObj.rows.push(r);
         mygrid.parse(jsonObj,"json");

[/code]

And the grid shows me the first row.However , if try to add another row, it still shows me only the first row, meaning only the first row gets parsed.

[code]var jsonObj = new Object();
jsonObj.total_count = 100;
jsonObj.pos = 0;

jsonObj.rows = [];
var r = new Object(); r.data = ["a", "b"]; jsonObj.rows.push(r);
r = new Object(); r.data = ["c", "d"]; jsonObj.rows.push(r);
         mygrid.parse(jsonObj,"json");

[/code]

I am not able to upload the file . So here is the code in sample.html

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>For demo purpose only :: &1</title>
	<link rel='STYLESHEET' type='text/css' href='codebase/dhtmlxgrid.css'>
	<link rel='STYLESHEET' type='text/css' href='codebase/skin/dhtmlxgrid_dhx_skyblue.css'>
	<script src='codebase/dhtmlxcommon.js'></script>
	<script src='codebase/dhtmlxgrid.js'></script>
	<script src='codebase/dhtmlxgrid_json.js'></script>
	<script src='codebase/dhtmlxgridcell.js'></script>	
</head>

<body>
	<h1>Configuration from XML</h1>
    <p>Configuration of grid can be loaded from XML file. You need only 2-3 script commands to get the grid up and running.</p>
	
	<div id="gridbox" style="width:600px; height:270px; background-color:white;"></div>
	
	<a href='#alfa' onClick="if(mygrid.setSerializationLevel){ser();} else {alert('Available in Pro Edition only')}">Serialize grid</a>

<script>
    mygrid = new dhtmlXGridObject('gridbox');
	mygrid.setImagePath('codebase/imgs/');
	mygrid.setSkin("dhx_skyblue")
	mygrid.setHeader("A,B")
	mygrid.setInitWidths("100,100");
	mygrid.init();
	
	mygrid.attachEvent("onDynXLS", function(pos, count){
		alert("Extra data request");
		return false;
	});

	mygrid.xmlFileUrl = "dummy";

	var jsonObj = new Object();
	jsonObj.total_count = 100;
	jsonObj.pos = 0;

	jsonObj.rows = [];
	var r = new Object(); r.data = ["a", "b"]; jsonObj.rows.push(r);
	r = new Object(); r.data = ["c", "d"]; jsonObj.rows.push(r);
	//alert("Set the rows JSON");
	
	/*
	[{
	    data: ["a", "b"]
	}, {data:["c", "d"]}
	];
	*/
	/*
	mygrid.parse({
		total_count:100,
		pos:0,
		rows:[["a","b"],[["c","d"]]]
	},"json");
	*/
	mygrid.parse(jsonObj,"json");

</script>

<a name="alfa">
<div id="alfa1"></div>
</a>

</body>
</html>

Also, there is no call to
grid.enableSmartRendering()

How does the grid know to fetch rows from the server and also the count of new rows to be fetched ?

Check the updated sample

The problem with second row adding in your sample was caused by missed row id ( it must be any unique value )
json_updated.zip (105 KB)

Hello, I tried your example because I’m developing an application with similar requerimets of smartRendering and custom parse. I need to capture “pos” and “count” to call my custom xml parse but the event onDynXLS is not firing when scrolling the grid. What can I do to fire the onDynXLS event every time the user scrolls the grid?

Any idea about why is the onDynXLS event not firing when scrolling?

Grid must know about possibility of dyn. loading for that

a) grid must be loaded with grid.load ( not grid.parse )
b) first loaded dataset must have total_count attribute with expected total count of row ( which must be greater than already loaded data to generate onDynXLS )

In case of json data, be sure to include ext/dhtmlxgrid_json.js on the page