Categories | Question details Back To List | ||
Image in Grid Hi I am working with DhtmlGrid with connector. I need to display in a grid text and pictures from my DB. Each name of my pic is save it inside of my data base like a string without the path, only the picture name (i.e "picture.jpg") This my current code mygrid = new dhtmlXGridObject('gridbox'); mygrid.setImagePath("./imgs/"); mygrid.setHeader("Picture, Value, Department, Name"); mygrid.setInitWidths("70,150,60,80"); mygrid.setColAlign("right,right,left,left"); mygrid.setColTypes("img,ed,ed,ed,ed"); mygrid.setColSorting("str,str,str,str,str"); mygrid.init(); mygrid.setSkin("light"); mygrid.load("myconnector.php?pk_id=<? echo $id ?>"); 1) I want to know how i can add a path in order to read the picture. Right now i can read the picture only if it is in my root. 2) How can i change the size.. my idea it's add a "width" and "heigh"t tag in order to re-size it like the IMG html propriety. 3) Is it possible to have auto size height for each cell in the GRID? Thank you :) Answer posted by Support on Apr 24, 2009 08:58 >>I want to know how i can add a path in order to read the picture There are two ways a) you can use beforeRender event of connector and add full path to the image during xml rendering or b) you can use setIconPath method of grid ( 2.0+ ), which allows to define separate path, which will be used for all non-skin images in grid. grid.setIconPath("some/path/here/"); // picture.jpg => some/path/here/picture.jpg >>) How can i change the size.. my idea it's add a "width" and "heigh"t You need to enable multiline mode grid.enableMultiline(true) as result grid will size its cell height based on content, and image will be fully visible. If you need to use custom size for images - the only solution is to use server side customization through beforeRender event Please check bottom post in next tread http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=8912&ssr=yes&s=beforeRender you can use same approach, just with <img> tag instead of <a> >>3) Is it possible to have auto size height for each cell in the GRID? Yes, grid.enableMultiline(true) purposed for it. Answer posted by Eduardo Pinetti on Apr 24, 2009 09:56 Hi again I was trying to work with the BeforeRender event... This is my new code in "myconnector.php" require("connector/grid_connector.php"); $res=mysql_connect("localhost","root","pass"); mysql_select_db("myDB"); $gridConn = new GridConnector($res,"MySQL"); $gridConn->render_sql("SELECT user.userPic,....blabla bla"); function custom_format($data){ $imagen="<img src='../pictures/".$data->get_value("user.userPic")."' width='60' height='80'>"; $data->set_value("user.userPic",$imagen); } $gridConn->event->attach("beforeRender","custom_format"); But Nothing is happeing.. In addition in found some confusions thing in the documentation here it uses: $grid->event->attach("beforeRender",my_code) without "" http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=8924&ssr=yes&s=event-%3Eattach(%22beforeRender%22 And here it uses: $grid->event->attach("beforeRender","custom_format"); with "" http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=8912&ssr=yes&s=event-%3Eattach(%22beforeRender%22 Thank you again Answer posted by Support on Apr 25, 2009 05:28 The render_sql ( and render_table ) is key command, when it executed - the rendering process occurs , so any new events attached after that will not be used in rendering process. Just change the order or commands as $gridConn = new GridConnector($res,"MySQL"); function custom_format($data){ $imagen="<img src='../pictures/".$data->get_value("user.userPic")."' width='60' height='80'>"; $data->set_value("user.userPic",$imagen); } $gridConn->event->attach("beforeRender","custom_format"); $gridConn->render_sql("SELECT user.userPic,....blabla bla"); //render initiated >>In addition in found some confusions thing in the documentation PHP parser automatically recognize unquoted text as a string, so while the usage of quoted parameter is a more correct use-case, both types of init will be processed correctly. Answer posted by Eduardo Pinetti on Apr 27, 2009 08:10 Hi Thank you about your response.. I tried to do that.. but it's still the same problem... nothing happening.. any error or msj to know where is the problem. Every data is displayed correct except the picture... if i change my client side code and i add mygrid.setIconPath("../pictures/") works.. but i can't change the size or any other html properties I don't know where is the problem :( Thank You Answer posted by Eduardo Pinetti on Apr 27, 2009 09:59 Hi I found the problem!!!! in my Select i use SELECT user.userPic, .... , .... FROM And in my get_value i have to use only "userPic" without the "user." Finally each label should be like that: $data->get_value("userPic") Thank you!!!! :) |