2017-07-18 61 views
0

我想在特定列上設置圖像,但是當我使用formatter設置時,我沒有得到預期的結果。圖像是壓倒一切的數據。在.jqGrid中的過濾條旁邊設置圖像

$(function() { 
 
    "use strict"; 
 
    
 
    $("#myDialogBox").dialog({ 
 
    autoOpen: false 
 
    }); 
 
    
 
    $("#grid").jqGrid({ 
 
    colModel: [ 
 
    { name: "BatchID", label: "Batch ID", align: "center"}, 
 
    { name: "Status", label: "Status", align: "center", formatter: "select", 
 
     formatoptions: { value: "CAN:Canceled; COM:Completed; PEN:Pending", defaultValue: "PEN" }, 
 
     stype: "select", searchoptions: { value: ":Pending;CAN:Canceled; COM:Completed"} }, 
 
    { name: "StartRunDate", label: "Start Run Date", align: "center", sorttype:"date", 
 
     formatter: function() { return "<img src='http://jqueryui.com/resources/demos/datepicker/images/calendar.gif' alt='calendar' />"; }, 
 
     formatoptions: { newformat: "d-M-Y" } }, 
 
    { name: "StartRunTime", label: "Start Run Time", align: "center", sorttype:"time", formatter: "time" }, 
 
    { name: "EndRunDate", label: "End Run Date", align: "center", editable:true, sorttype:"date" }, 
 
    { name: "EndRunTime", label: "End RunTime", align: "center", editable:true, sorttype:"time" }, 
 
    { name: "Action", label: "Action", align: "center", formatter: "showlink"}, 
 
    { name: "JobID", label: "Job ID", align: "center" }, 
 
    { name: "JobName", label: "Job Name", align: "center"}, 
 
    { name: "ConceptName", label: "Concept Name", align: "center" }, 
 
    { name: "StartDate", label: "Start Date", align: "center" }, 
 
    { name: "EndDate", label: "End Date", align: "center" }, 
 
    { name: "Frequency", label: "Frequency", align: "center", 
 
     \t formatter: "select", 
 
     formatoptions: { value: "ALL:All; DAI:Daily; WEK:Weekly", defaultValue: "ALL" }, 
 
     stype: "select", 
 
     searchoptions: { value: ":All; DAI:Daily; WEK:Weekly" } }, 
 
    { name: "QueryLink", label: "Query Link", align: "center", 
 
     formatter: function() { return '<button class="popup-trigger">Pop Up</button>' } }, 
 
    { name: "Submitter", label: "Submitter", align: "center"} 
 
    ], 
 
    data: [ 
 
    { BatchID: "1", Status: "Pending", StartRunDate: "7/12/2017", StartRunTime:"12:00", EndRunDate: "7/12/2017", 
 
     EndRunTime:"1:00", Action: "Cancel Delivery", JobID: "123", JobName: "Test", ConceptName: "CPK", StartDate: "7/12/2017", EndDate: "7/12/2017", Frequency: "All", QueryLink: "Link", Submitter: "John Doe" 
 
    }], 
 
    iconSet: "fontAwesome", 
 
    rownumbers: true, 
 
    sortname: "invdate", 
 
    sortorder: "desc", 
 
    caption: ".jqGrid Test" 
 
    }).jqGrid('filterToolbar', {autoSearch: true}).on('click', '.popup-trigger', function() { 
 
    $("#myDialogBox").dialog("open"); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.6/js/jquery.jqgrid.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.0/css/ui.jqgrid.min.css" rel="stylesheet"/> 
 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet"/> 
 

 
<table id="grid"></table> 
 
<div id="myDialogBox" title="Basic dialog"></div>

預期的結果:想要日曆旁邊x圖標。

enter image description here

缺少什麼我在這裏?這裏有什麼.jqGrid限制?

+0

我不知道,我明白你的問題。當前代碼格式化輸入數據'「7/12/2017」'作爲圖標。如果您在「StartRunDate」列的過濾器工具欄中輸入字符串「7/12/2017」,則會獲得按值過濾的數據:一行。如果您在過濾器工具欄中輸入任何其他值爲'7/12/2017'(例如'8/12/2017'),然後按Enter鍵,則不會顯示任何行。 – Oleg

+0

@ Oleg抱歉的混淆。我希望圖標所在的'x'和'7/12/2017'旁邊有'日曆'圖標。搜索很好。我在設置濾鏡欄旁邊的圖標時遇到問題。我現在正在做的是用我不想要的圖像取代「2017年7月12日」。 – CSharper

回答

1

我不確定我是否正確理解您的要求。下面你可以找到你的代碼的修改與在StartRunDatecolModel一些變化和小的額外CSS規則

$(function() { 
 
    "use strict"; 
 
    
 
    $("#myDialogBox").dialog({ 
 
    autoOpen: false 
 
    }); 
 
    
 
    $("#grid").jqGrid({ 
 
    colModel: [ 
 
    { name: "BatchID", label: "Batch ID", align: "center"}, 
 
    { name: "Status", label: "Status", align: "center", formatter: "select", 
 
     formatoptions: { value: "CAN:Canceled; COM:Completed; PEN:Pending", defaultValue: "PEN" }, 
 
     stype: "select", searchoptions: { value: ":Pending;CAN:Canceled; COM:Completed"} }, 
 
    { name: "StartRunDate", label: "Start Run Date", align: "center", sorttype:"date", 
 
     formatter: function (cellval, opions, rawdata, act) { 
 
      return $.fn.fmatter.call(this, "date", cellval, opions, rawdata, act) + 
 
"&nbsp;<img src='https://jqueryui.com/resources/demos/datepicker/images/calendar.gif' alt='calendar' style='display:inline-block;vertical-align: middle;' />"; }, 
 
     formatoptions: { srcformat: "m/d/Y" }, 
 
     searchoptions: { 
 
      sopt: ["eq", "ne", "lt", "le", "gt", "ge"], 
 
      attr: { 
 
       placeholder: "m/d/yyyy", 
 
       style: "width: 110px; display: inline-block;" 
 
      }, 
 
      dataInit: function (elem, options) { 
 
       $(elem).datepicker({ 
 
        showOn: "button", 
 
        buttonImage: "https://jqueryui.com/resources/demos/datepicker/images/calendar.gif", 
 
      buttonImageOnly: true 
 
       }); 
 
      } 
 
     } }, 
 
    { name: "StartRunTime", label: "Start Run Time", align: "center", sorttype:"time", formatter: "time" }, 
 
    { name: "EndRunDate", label: "End Run Date", align: "center", editable:true, sorttype:"date" }, 
 
    { name: "EndRunTime", label: "End RunTime", align: "center", editable:true, sorttype:"time" }, 
 
    { name: "Action", label: "Action", align: "center", formatter: "showlink"}, 
 
    { name: "JobID", label: "Job ID", align: "center" }, 
 
    { name: "JobName", label: "Job Name", align: "center"}, 
 
    { name: "ConceptName", label: "Concept Name", align: "center" }, 
 
    { name: "StartDate", label: "Start Date", align: "center" }, 
 
    { name: "EndDate", label: "End Date", align: "center" }, 
 
    { name: "Frequency", label: "Frequency", align: "center", 
 
     \t formatter: "select", 
 
     formatoptions: { value: "ALL:All; DAI:Daily; WEK:Weekly", defaultValue: "ALL" }, 
 
     stype: "select", 
 
     searchoptions: { value: ":All; DAI:Daily; WEK:Weekly" } }, 
 
    { name: "QueryLink", label: "Query Link", align: "center", 
 
     formatter: function() { return '<button class="popup-trigger">Pop Up</button>' } }, 
 
    { name: "Submitter", label: "Submitter", align: "center"} 
 
    ], 
 
    data: [ 
 
    { BatchID: "1", Status: "Pending", StartRunDate: "7/12/2017", StartRunTime:"12:00", EndRunDate: "7/12/2017", 
 
     EndRunTime:"1:00", Action: "Cancel Delivery", JobID: "123", JobName: "Test", ConceptName: "CPK", StartDate: "7/12/2017", EndDate: "7/12/2017", Frequency: "All", QueryLink: "Link", Submitter: "John Doe" 
 
    }], 
 
    iconSet: "fontAwesome", 
 
    rownumbers: true, 
 
    sortname: "invdate", 
 
    sortorder: "desc", 
 
    caption: ".jqGrid Test" 
 
    }).jqGrid('filterToolbar', {autoSearch: true}).on('click', '.popup-trigger', function() { 
 
    $("#myDialogBox").dialog("open"); 
 
    }); 
 
});
.ui-search-input img.ui-datepicker-trigger { 
 
    display: inline-block; 
 
    vertical-align: middle; 
 
    margin-bottom: 1px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/jquery.jqgrid.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.14.1/css/ui.jqgrid.min.css" rel="stylesheet"/> 
 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" rel="stylesheet"/> 
 

 
<table id="grid"></table> 
 
<div id="myDialogBox" title="Basic dialog"></div>

+0

這非常有幫助。我修改了一下代碼以獲得所需的結果。 [這](https://jsfiddle.net/gunjan_prmr/153xxhL9/)是我正在尋找。對困惑感到抱歉。 – CSharper

+0

@CSharper:不客氣! – Oleg