Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image column in jqGrid?

Tags:

jquery

jqgrid

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(document).ready(function() {
        var TheGrid ;
         var resp;
        jQuery("#registerUsers").jqGrid({
                url: 'EventsList.aspx',
                datatype: "json",
                colNames: ['Name', 'Company Name', 'Responsible Name', 'Date/Time', 'Id'],
                colModel: [{ name: 'GuestName', index: 'GuestName', width: 150, editable: true, editoptions: {readonly: true, size: 10} },
                          { name: 'CompName', index: 'CompName', width: 150, editable: false, editoptions: { readonly: true, size: 10} },
                          { name: 'RespName', index: 'RespName', width: 150, editable: false, editoptions: { readonly: true, size: 10} },
                          { name: 'RegisterDate', index: 'RegisterDate', width: 150, editable: false, editoptions: { readonly: true, size: 10} },
                          { name: 'Register_Id', index: 'Register_Id', width: 100, align: 'left', formatter: checkboxFormatter },
                        ],
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: jQuery('#Userpager'),
                sortname: 'Register_Id',
                viewrecords: true,
                sortorder: "desc",
                imgpath: '/scripts/themes/steel/images',
                caption: "Registered Users"
            });
        });
        jQuery("#registerUsers").jqGrid('navGrid', '#Userpager', { edit: false, add: false, del: false });

  function checkboxFormatter(el, cval, opts) {
            debugger;
            cval = cval + ""; cval = cval.toLowerCase();
            //          var bchk = cval.search(/(false|0|no|off|n)/i) < 0 ? " checked=\"checked\"" : ""; 
            var UserId = jQuery("#registerUsers").getCell(RowId, 'Register_Id');
            $(el).html("<center><img src='../images/gnome-session-logout.png' width='15px' height='15px'  onclick=javascript:LogOutUser(" + UserId + ");/></center>");
            //          <input type='checkbox' onclick=\"ajaxSave('" + opts.rowId + "', this);\" " + bchk + " value='" + cval + "' offval='no' />



        } 

Please help me

Thank You Ritz

like image 411
Ritz Avatar asked Feb 18 '10 11:02

Ritz


2 Answers

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

like image 180
Justin Moore Avatar answered Nov 13 '22 05:11

Justin Moore


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.

like image 2
Justin Ethier Avatar answered Nov 13 '22 06:11

Justin Ethier