image column in jqGrid?

后端 未结 4 359
面向向阳花
面向向阳花 2020-12-29 10:01

I want a image column in my jQGrid,I have used a formatter,but doesnot work,please give me the solution for this.

my code is as follows:

jQuery(docum         


        
相关标签:
4条回答
  • 2020-12-29 10:18

    See can-you-have-images-or-any-custom-html-displayed-in-jquery-grid-jqgrid-cells for instructions on displaying images in cells.

    Basically, it looks like you may need to remove quotes from your src element.

    0 讨论(0)
  • 2020-12-29 10:35

    i found this solution.

    If in your page you include only the table by inserting the scripts and stylesheets and after including grid.php page, you can format the cell to display image this way:

    Put the code below in your grid.php:

    $grid->setColProperty("COLUMN NAME", array("formatter"=>"js:formatImage"));
    

    Then, put in a string variable, the java script for formatImage function this way:

    $IMAGE_FORMAT_STRING = <<<IMAGE_FORMAT_FUNCTION
    function formatImage(cellValue, options, rowObject) {
        var imageHtml = "";
        if(cellValue){
            if(cellValue.indexOf("_thumb") == -1){
                imageHtml = '<div><a href="' + cellValue + '" title="" target="_blank">' + cellValue + '</a></div>';    
            }else{
                imageHtml = '<div class="gallery"><a href="' + cellValue.replace('_thumb', '') + '" title=""><img src="' + cellValue + '" width="50" height="50" alt="" border="0"/></a></div>';
            }
        }
        return imageHtml;
    }
    function unformatImage(cellValue, options, cellObject) {
        return $(cellObject.html()).attr("originalValue");
    }
    IMAGE_FORMAT_FUNCTION;
    

    and above the grid->renderGrid, put set the JavaScript Code this way:

    $grid->setJSCode($IMAGE_FORMAT_STRING);
    

    I hope it helps somebody!

    0 讨论(0)
  • 2020-12-29 10:39

    A simple solution could be made directly from the query:

    select idres, 'HTML-IMG-SRC=images/tick_' || reserved || '.png' as reserved, indate, outdate from table; -- querying postgres

    Where reserved is 0 or 1 and reflects in the image file name "tick_1.png" or "tick_0.png" depending on the field's value of 'reserved'

    Hope it helps

    0 讨论(0)
  • 2020-12-29 10:43

    you can just return the img tag as a string in the formatter eg:

    function  unitsInStockFormatter(cellvalue, options, rowObject) {
        var cellValueInt = parseInt(cellvalue);
        if (cellValueInt > 10)
          return "<img src='../../Content/images/ui-flag_green.png' alt='" + cellvalue + "'title='" + cellvalue + "' />";
        else if (cellValueInt > 0)
          return "<img src='../../Content/images/ui-flag_blue.png' alt='" + cellvalue + "'title='" + cellvalue + "' />";
        else
          return "<img src='../../Content/images/ui-flag_red.png' alt='" + cellvalue + "'title='" + cellvalue + "' />";
      }; 
    

    as described here: http://tpeczek.com/2009/11/jqgrid-and-aspnet-mvc-formatting.html

    0 讨论(0)
提交回复
热议问题