add image in jqgrid

摘要:add image in jqgrid

     function JsonQuery_OnComplete(){
        //Clear  when we generate Grid
        $("#UserList").GridUnload();
        jQuery("#UserList").jqGrid({
                        //GetData - OnlineUserList
                        url: '@Url.Action("OnlineUserListView", "System")',
                        mtype: "POST",
                        rownumbers: true,
                        rownumWidth: 40,
                        datatype: "json",
                        height: 220,
                        colNames: ['狀態','用戶名', '登錄時間', '預計超時時間', 'IP地址'],
                        colModel: [
                    { name: 'Status', index: 'Status', align: 'center', width: 40,formatter: unitsInStockFormatter },
               { name: 'UserName', index: 'UserName', width: 200 },
                    { name: 'LoginTime', index: 'LoginTime', width: 150, sortable: false, formatter: 'date', formatoptions: { newformat: '@Tecsys.Web.OMS.WebEngine.Core.Contants.JQGridDateFormat.YYYYMMDDHHMMSS'}},
                    { name: 'ExpireTime', index: 'ExpireTime', width: 150, formatter: 'date' , formatoptions: { newformat: '@Tecsys.Web.OMS.WebEngine.Core.Contants.JQGridDateFormat.YYYYMMDDHHMMSS'}},
                    { name: 'IpAddress', index: 'IpAddress', width: 150 }
               ],
                        jsonReader: {
                            repeatitems: false,
                            root: function (obj) { return obj.Data; },
                            page: function (obj) { return obj.Page; },
                            total: function (obj) { return obj.Total;},
                            records: function (obj) { return obj.Records; }
                        },
                        prmNames: {
                            page: 'PageIndex',
                            rows: 'PageSize',
                            sort: 'Sort',
                            order: 'OrderBy'
                        },
                        postData: {
                            UserID: function () { return $("input[name=txtUserID]").val(); },
                        },
                        loadonce: true,
                        rowNum: 10,
                        rowList: [10, 20, 30],
                        pager: '#Pager',
                        sortname: 'Username',
                        shrinkToFit: false,
                        viewrecords: true,
                        sortorder: "asc",
                        caption: '在線會員列表'
                    });
 
                    jQuery("#UserList").jqGrid('navGrid', '#Pager', { edit: false, add: false, del: false });
                       // add column chooser button
             
     }
 
function unitsInStockFormatter(cellvalue, options, rowObject) {
     var cellValueInt = parseInt(cellvalue);
     if (cellValueInt == 0)
       return "<img src='@Url.Content("~/Content/images/0.png")' alt='" + cellvalue + "' title='" + cellvalue + "' />";
     else if (cellValueInt == 1)
       return "<img src='@Url.Content("~/Content/images/1.png")' alt='" + cellvalue + "' title='" + cellvalue + "' />";
     else
       return "<img src='@Url.Content("~/Content/images/2.png")' alt='" + cellvalue + "' title='" + cellvalue + "' />";
   }; 
</script>

人生到處知何似
應似飛鴻踏雪泥