0

在我的数据库中,我在一列中有两个选项:

  1. /上传/1369839038.zip
  2. 无效的

现在我已经格式化了“电子邮件”列,所以它显示为一个链接,

formatter:function(cellvalue, options, rowObject){
                return '<a href="' + cellvalue + '"target="_blank">FILES </a> '
            } }

但是我想制作一个格式化程序,如果它具有“NULL”,则显示为空白,如JQGRID 显示空白而不是 Null或显示为我已经拥有的链接。我想为这个“附件”列将两者结合在一个格式化程序中,以便它根据数据显示,无论是链接还是空白。请一些帮助,非常感谢。

我的 JQgrid

    $(function(){ 
      $("#list").jqGrid({
        url:'request.php',
        editurl: "jqGridCrud.php",
        datatype: 'xml',
        mtype: 'GET',
        height: 'AUTO',
    width: 850,
    scrollOffset:0,
    hidegrid: false,

    colNames:['id','Project', 'Assigned To','Assign Date','Check Date','Due Date','Attachments','Notes',""],
    colModel :[ 
      {name:'id', index:'id', width:28, align: 'center'}, 
      {name:'name', index:'name', width:170, align:'left',editable:true, editoptions:{
            size:60} }, 
      {name:'id_continent', index:'id_continent', width:50, align:'right',editable:true,edittype:'select', 
      editoptions:{value: "Henry:Henry; Ramon:Ramon; Paul:Paul" },mtype:'POST'  }, 

      {name:'lastvisit', index:'lastvisit', width:55, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/d/yy',editable:true, edittype: 'text',mtype:'POST' ,       editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/d/yy'});}}} ,


      {name:'cdate', index:'cdate', width:55, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/d/yy', edittype: 'text',editable:true ,mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/d/yy'});}}} ,

      {name:'ddate', index:'ddate', width:55, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/d/yy',date:'true',editable:true, edittype: 'text',editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/d/yy'});}}} ,


      {name:'files', index:'files', width:50,align:'center',sortable:false,mtype:'POST',formatter:function(cellvalue, options, rowObject){
            return '<a href="' + cellvalue + '"target="_blank">FILES </a> '
        } },

        {name:'notes', index:'notes', width:100, align:'left',sortable:false, editable:true,edittype:'textarea', editoptions:{
            rows:5,cols:60,maxlength:200} },    

        {name:'act', index:'act',width:30 ,align:'left', sortable:false,formatter: "actions",cellattr: function () { return ' title="Delete Project"'; },
formatoptions: {
    keys: true,
     deltitle: 'delete',
    delbutton: true,
    editbutton:false,
    delOptions: {
        url: 'delete-perm.php',
        afterShowForm: function ($form) {
    $("#dData", $form.parent()).click();
},
        msg: "Remove Selected Project?",
        bSubmit: "Remove",
        bCancel: "Cancel"
    }
}}, 
    ],
    pager: '#pager',

    rowNum:30,
    rowList:[30,40,80],
    sortname: 'ddate',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    caption: 'Current Assignments',


    ondblClickRow: function(rowid) {

    $(this).jqGrid('editGridRow', rowid,
                        {width:550,Height:550,recreateForm:true,closeAfterEdit:true,
                         closeOnEscape:true,reloadAfterSubmit:true, modal:true,mtype:'post',top:350,left: 30});}


            });

 jQuery.extend(jQuery.jgrid.nav, {
        deltitle: '',
        delcaption: 'Project Complete'


    },{delicon: "ui-icon-circle-check",deltext: "Project Complete"});   

    $("#list").jqGrid("navGrid", "#pager", { add: false, search: false, refresh:false,edit:false }).navButtonAdd('#pager',{


                                caption:"Export to Excel", 
                                buttonicon:"ui-icon-save", 
                                onClickButton: function () {
        jQuery("#list").jqGrid('excelExport', { url: 'ExportExcel.php' });
}, 
                                position:"last"
                            });
    // setup grid print capability. Add print button to navigation bar and bind to click.
    setPrintGrid('list','pager','Current Assignments');

});
4

1 回答 1

1

我不确定我是否正确理解了您的问题,但为什么不尝试使用以下自定义格式化程序:

function (cellvalue, options, rowObject) {
    if (cellvalue === undefined || cellvalue === null || cellvalue === 'NULL') {
        return '&nbsp;'; // or just ""
    }
    return '<a href="' + cellvalue + '"target="_blank">FILES </a>';
}
于 2013-10-06T16:09:09.513 回答