Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Paul Dunn on Apr 01, 2009 17:07
open dhtmlx forum
URL cell formatting

I am using a trial PRO version of DHTMLXgrid.

The grid is populated using DHTMLXconnector.

I want to:

Make the values for a column hyperlinks that will open in the active window.

For example:
My grid has two columns: "Product ID" and "Product Name".
The "Product ID" cell contains the value: 1234

I would like to have a hyperlink in the ProductID column like this: <a href="viewProduct.php?pid=1234">1234</a>

Any advice on how to do this with the grid and connector would be appreciated.


Thanks in advance.
Answer posted by dhxSupport on Apr 02, 2009 04:29
You can use "link" excell type. Threat value as link source, renders as link (A tag)
The corresponding cell value in XML should be a "^" delimited list of following values:
1st - Link Text
2nd - URL (optional)
3rd - target (optional, default is _blank)

  Dummy link
  Real link^http://dhtmlx.com
  Real link^http://dhtmlx.com^_blank

  Real link^javascript:doSomething()^_self

Using dhtmlxConnectors's event you can change responce from the server in the appropriate way (beforeRender - event occurs after data has been selected from the database but before its outputting to client, beforeProcessing - event occurs before beforeInsert, beforeUpdate, beforeDelete events occur. The beforeProcessing method occurs for all these operations. It can be cancelled in the same way as the aforementioned events)


Answer posted by Paul Dunn on Apr 02, 2009 05:12

Thanks for your reply.

I understand what you are saying because I have read the same information in the documentation.

However the documentation is not so good - There's also a missing link for the different methods for client side components in the "beforeRender" section of the documentation  - (http://www.dhtmlx.com/docs/products/dhtmlxConnector/doc/View?docid=dhhqnnw2_88cm84z4dd)

Please could you give a clear example as its not obvious how the beforeRender event gets a $column, or how how I can format the data to my requirements.

Thanks again. 

Answer posted by Support on Apr 02, 2009 06:26
The server side code may look as 

function custom_format($data){
    $link="<a href='viewProduct.php?id=".$data->get_value("ProductId")."'>".$data->get_value("ProductName")."</a>";
    $data->set_value("ProductName",$link)
}
$grid->event->attach("beforeRender","custom_format");

Above code uses HTML tags for link formating, but if you are using link type for the column in grid, you can use more simple format described in previous post. 

>>There's also a missing link for the different methods for client side components in the "beforeRender"
Link will be fixed in nearest time, it must points to the next document
              http://dhtmlx.com/docs/products/dhtmlxConnector/doc/api.html#cc_api_a


>> how the beforeRender event gets a $column
custom function assigned to event receives data object ( basically it is wrapper around hash of values fetched for the row from DB ) , you can use get_value, set_value to change content for any column
The "ProductId" and "ProductName" names just an example, you need to use the same column names , as was specified in last parameter or render_table ( render_sql ) 
Answer posted by Paul Dunn on Apr 02, 2009 14:00
Perfect - Excellent support. Thanks again.