2013-10-23 71 views
0

作爲一名設計師,當沒有數據可以讓人失望的時候,我就會對美麗的「空白狀態」信息產生興趣,鼓勵用戶採取行動。 (事實上​​,是一個整體的tumblr博客獻給這樣的:http://emptystat.es/有沒有辦法使用Flexigrid顯示有吸引力的「空狀態」消息?

由於Flexigrid的快樂和忠誠的用戶,我很想能夠代替空狀態消息時,系統我建立沒有任何搜索結果要顯示在網格中(例如「您沒有待處理的請求!單擊新建開始」)。理想情況下,這樣一個空狀態的消息將是圖形和比單獨的行大,並將取代網格的全部內容。任何人都可以提供一些建議,關於如何在沒有行返回時使用圖形空狀態消息替換flexigrid的內容?

謝謝!

回答

0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>Flexigrid</title> 
    <link rel="stylesheet" type="text/css" href="../css/flexigrid.css"> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
    <script type="text/javascript" src="../js/flexigrid.js"></script> 
    </head> 
    <body> 
    <p>This is a sample implementation attached to a form, to add additional parameters.</p> 

    <form id="sform"> 
     <p> 
     The values you entered will be place in name column for demo's sake.<br /> 
     Value 1 : <input type="text" name="val1" value="" autocomplete="off" /><br /> 
     Value 2 : Is a hidden input with value 3<input type="hidden" name="val2" value="3" /><br /> 
     Value 3 : 
     <select name="val3"> 
      <option value="1">One</option> 
       <option value="2">Two</option> 
       <option value="3">Three</option> 
       <option value="4">Four</option> 
       <option value="5">Five</option> 
     </select><br /> 
     Value 4 : <input type="checkbox" name="val4" id="val4" value="4" /><label for="val4">This will pass a value 4 if checked</label> 
     </p> 
     <p> 
      <input type="submit" value="Submit" /> 
     </p> 
    </form> 
    <button onclick=hide()>HIDE</button> 
    <button onclick=show()>SHOW</button> 
    <table id="empty1" style="display:none"> 
    <tr><td><b>Please</b> <u>fill some</u> data</td></tr> 
    </table> 
    <table id="flex1" style="display:block"> 
    <tr><td>1</td></tr> 
    <tr><td>2</td></tr> 
    <tr><td>3</td></tr> 
    </table> 
    <script type="text/javascript"> 
    var old = undefined 
    function hide() { 
     if (old == undefined) { 
      old = flex1.innerHTML 
      flex1.innerHTML = empty1.innerHTML 
     } 
    } 
    function show() { 
     if (old != undefined) { 
      flex1.innerHTML = old 
      old = undefined 
     } 
    } 
    $("#flex1").flexigrid({ 
     url: 'post2.php', 
     dataType: 'json', 
     colModel : [ 
      {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
      {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
      {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
      {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
      {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
      ], 
     searchitems : [ 
      {display: 'ISO', name : 'iso'}, 
      {display: 'Name', name : 'name', isdefault: true} 
      ], 
     sortname: "iso", 
     sortorder: "asc", 
     usepager: true, 
     title: 'Countries', 
     useRp: true, 
     rp: 15, 
     showTableToggleBtn: true, 
     width: 700, 
     onSubmit: addFormData, 
     height: 200 
    }); 

    //This function adds paramaters to the post of flexigrid. You can add a verification as well by return to false if you don't want flexigrid to submit   
    function addFormData(){ 
     //passing a form object to serializeArray will get the valid data from all the objects, but, if the you pass a non-form object, you have to specify the input elements that the data will come from 
     var dt = $('#sform').serializeArray(); 
     $("#flex1").flexOptions({params: dt}); 
     return true; 
    } 

    $('#sform').submit(function(){ 
     $('#flex1').flexOptions({newp: 1}).flexReload(); 
     return false; 
    }); 
    </script> 
    </body> 
    </html> 
+0

對不起,我想我沒」在我原來的問題中非常明確。我正在尋找一個專門涉及Flexigrid jQuery數據網格對象的解決方案,如下所示:http://flexigrid.info/ – pbanka

+0

是的,這就是我所提到的。您應該將flexgrid與HTML表關聯起來。 Flexigrid將修改各種表格屬性並添加一些裝飾以使其有用。然後,您可以使用經典的Javascript或jQuery控制關聯的HTML表格。使用table.innerHTML將其更改爲任何你想要的。 – exebook

0

我使用dojo解決了這個問題,因爲我們已經在我們的網站中使用這個框架。我確信在不同的圖書館中有類似的解決方案。基本上我創建了一個新的類,創建flexigrid後,通知如果在flexigrid沒有數據,如果指定了一個放在一個背景圖像表:

dojo.provide("app.components.EmptyStateFlexigrid"); 
dojo.require("dijit._Widget"); 

// Provides a custom Flexigrid with an empty-state 
dojo.declare("app.components.EmptyStateFlexigrid", [dijit._Widget], { 
    emptyStateUrl: null, 
    id: null, 
    url: null, 
    colModel: null, 
    buttons: null, 
    sortField: null, 
    sortOrder: null, 
    height: null, 
    usePager: null, 
    resizable: null, 

    // Create the flexigrid object 
    makeGrid: function() { 
     var gridObj = $('#' + this.id + "_flexigrid"); 
     gridObj.flexigrid({ 
      url: this.url, 
      dataType : 'json', 
      colModel : this.colModel, 
      buttons : this.buttons, 
      sortname : this.sortField, 
      sortorder : this.sortOrder, 
      height: this.height, 
      usepager : this.usePager, 
      resizable: this.resizable, 
      onSuccess: this.checkEmptyState, 
      useRp : true, 
      rpOptions: [2, 10, 15, 20, 30, 50], 
      rp : 15, 
      showTableToggleBtn : false 
     }); 
    } 
}, 

// EMPTY-STATE: make a nice graphic here if there is no data 
// Note that "this" is a flexigrid object 
checkEmptyState: function() { 
    var self = dijit.byId(this.id); 
    var gridObj = $('#' + this.id + "_flexigrid"); 
    if (gridObj[0].id === this.id + '_flexigrid') { 
     var gridChildren = gridObj.children(); 
     if (gridChildren.length === 0) { 
      var gblocks = $(".gBlock"); 
      for (var i = 0; i < gblocks.length; i++) { 
       var styleObj = gblocks[i].style; 
       // The only way I could find to identify "our" flexigrid (if there is 
       // more than one on the page) is to test to see if the height is the 
       // same as our height. Kind of a lousy hack, but the best I could figure 
       // out. -pbanka 
       if (styleObj.height == self.height + 'px') { 
        styleObj.backgroundSize = "450px"; 
        styleObj.backgroundRepeat = "no-repeat"; 
        styleObj.backgroundImage = "url('" + self.emptyStateUrl + "')"; 
       } 
      } 
     } 
    } 
}, 
相關問題