Dojo xmlstore和数据网格项计数



我有一个xml存储调用url并从数据库获取数据。当有数据从数据库返回时,它必须显示在数据网格中。当没有数据时,它必须显示适当的错误消息。我有以下js文件:

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

我的问题终于解决了。

    dojo.connect(dataGrid,"_onFetchComplete",function(items){
console.log(datagrid.rowCount);
        }
    })

谢谢!

相关内容

  • 没有找到相关文章

最新更新