2015-10-15 44 views
0

我是一個調用url並從數據庫獲取數據的xml存儲。當有數據從數據庫返回時,它必須顯示在數據網格中。當沒有數據時,它必須顯示適當的錯誤信息。 我有以下js文件。dojo xmlstore和數據網格項目數

require(["dojo/date/locale","dojox/grid/DataGrid","dojox/data/XmlStore","dijit/registry", "dojo/fx","dijit/form/ValidationTextBox", "dojo/dom-form", "dojo/dom", "dojo/on", "dojo/request","dojox/xml/parser", "dojo/ready","dojo/domReady!"], 
     function(locale,DataGrid,XmlStore,registry,coreFx,dijit, domForm, dom, on, request, parser, ready){ 

    var format; 
    var siteId; 
    var phoneNum; 
    var grid; 
    var dataGrid=new DataGrid({ 
     autoWidth:true, 
     autoHeight:true, 
     clientSort:true, 
       structure: [ 
        {name:"Order ID", field:"orderId"}, 
        {name:"Sender", field:"senderName"}, 
        {name:"Recipient", field:"recipientName"}, 
        {name:"Phone Number", field:"phone"}, 
        {name:"Gift Amount", field:"amount"} 
        ] 
    },"showGrid"); 
    dataGrid.startup(); 

    on(dom.byId("submitButton"), "click", function(){ 

     ready(function() 
       { 
      submitValue(); 

       }); 
    }); 

    on(dom.byId("printGiftcard"), "click", function(){ 

     ready(function() 
       { 

      window.print(); 
       }); 
    }); 


    function submitValue(){ 

     grid=registry.byId("showGrid"); 
     grid.set("store", null); 
     grid.filter(); 
     document.getElementById("outcomeMessage").innerHTML=""; 
     var orderNumber= document.getElementById("orderNumber"); 
     var num=orderNumber.value; 
     if(num==""){ 
      document.getElementById("outcomeMessage").innerHTML="Please enter Order number"; 
      return; 
     } 

     var myStore= new XmlStore({ 
      url:"/hello/"+num, 
      urlPreventCache : false, 
      query:{}, 
      queryOptions:{}, 
      onComplete:sizeCount 
     }); 

     var sizeCount = function(items,request){ 
      console.log(items.length); 
      if(items.length == 0){ 
       document.getElementById("outcomeMessage").innerHTML="data not found"; 
      } 

     } 
     var request = myStore.fetch({query:{},queryOptions:{},onComplete:sizeCount}); 


     grid=registry.byId("showGrid"); 
     grid.set("store", myStore); 
     //grid.filter(); 



    } 

}); 

The problem is it is calling database twice now in order to check the number of items returned.Once to set the store for the grid and other to check if the data returned is null.Can someone give me a simplified solution for this. 

Thanks 

回答

1

我終於解決了我的問題。

dojo.connect(dataGrid,"_onFetchComplete",function(items){ 

console.log(datagrid.rowCount); 
     } 
    }) 

謝謝!

+0

請提供有關如何解決問題的更多解釋! – eliasah

+0

我解決了上述解決方案 – sanvica