dojo xmlstore and data grid item count

314 Views Asked by At

I ahve an xml store that calls an url and fetch data from database. It has to be displayed in the data grid when there is data returned from the database. When there is no data, it has to show appropriate error message. I have the following js file.

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

There are 1 best solutions below

1
On BEST ANSWER

I finally resolved my issue.

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

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

Thanks!