Hi,
Because I don’t want to have sql statements exposed in a php page file (but a class method instead), I use render_array in the page file. However, there’re thousands of records, so I’m trying to simulate the dynamic loading on server side. There’s no problem with the later loading with posStart and count, but for the first time loading, how can I give the total number of rows to the grid?
Really nice, with $conn->add_top_attribute(“some_data”) I can add userdata for the whole grid now, not only for rows.
They appear as extra attributes of the rows element of the rendered output, as far as I can see in Firebug.
But next question is: how can I retrieve these values on the client side and use them?
Actually, what would make even more sense, is to have a method to insert userdata for the whole grid when using connector, since the docs already describe which xml tags are needed for this:
some data //userdata related to the whole grid
<row id=1 ....
These can simply be retrieved with grid.getUserdata(rowId, value) on the client, by leaving the rowId to a empty string.
But is not clear to me how these tags can be inserted when using connector. There is a php method to set_userdata($name, $value) for a data item (so for each row), but unfortunately there is none for inserting userdata directly after the tag.
Any suggestions how to create one, as an extension of GridConnector perhaps?
Thanks, Stanislav. I already tried to use the beforeOutput event. For some reason, when I echo data before the actual output that way (like in the manual), I don’t see anything of that appearing in the browser or even in Firebug. Maybe because this way it is placed before the very first <? xml ?> tag, so maybe it gets ignored in a later stage of processing?
Although I see how to echo extra data before connector outputs the rest of it, I don’t see how to attach extra data after the first and tag this way, unless I completely process the whole output in custom code. Of course I try to use connector just to avoid that.
Well, for now I use this solution. Maybe other people are interested in it, and very maybe, it finds its way to the source code, so we do not need to extend ourselves anymore. It requires only minimal changes of the original code: I only appended .$this->userdata; to 3 lines of the original code, all in just one function.
[code]
// Extension of GridConnector to send global userdata for whole grid
Class GridConnector_usrdata extends GridConnector{
protected function xml_start(){
$attributes = "";
foreach($this->attributes as $k=>$v)
$attributes .= " ".$k."='".$v."'";
if ($this->dload){
if ($pos=$this->request->get_start())
return "<rows pos='".$pos."'".$attributes.">".$this->userdata;
else
return "<rows total_count='".$this->sql->get_size($this->request)."'".$attributes.">".$this->userdata;
}
else
return "<rows".$attributes.">".$this->userdata;
}
public function add_userdata($key, $value){
$this->userdata .="<userdata name='".$key."'>".$value."</userdata>";
}
}[/code]
Now we can use the extended connector:
$conn = new GridConnector_usrdata($mysqli, "MySQLi");
$conn->add_userdata("userdata_name",$user_data_value);
On client side, we can now use the global userdata for the grid. Because of asynchronous nature of ajax, in most cases we have to use a callback function. In this example, userdata are written to a statusbar: