jQWidgets Forums

jQuery UI Widgets Forums Plugins Data Adapter How to use an asynchronous method in data adapter.

This topic contains 4 replies, has 2 voices, and was last updated by  jittopjose 11 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author

  • jittopjose
    Participant

    Hi,
    I am using data adapter as a source for text box to enable dynamic auto complete. At present the method is a synchronous and this method is specified in localdata option. My existing code is as follows:

    self.productSource = function (query, response) {
    	    var dataAdapter = new $.jqx.dataAdapter
    	    (
    	        {
    	            localdata: _productModel.getAllProductsAutoComplete(query),
                    datatype: "array"
    	        },
    	        {
    	            autoBind: true,
    	            formatData: function (data) {
    	                data.name_startsWith = query;
    	                return data;
    	            },
    	            loadComplete: function (data) {
    	                if (data.length > 0) {
    	                    response($.map(data, function (item) {
    	                        return {
    	                            label: item.ProductName,
    	                            value: item.ProductName
    	                        }
    	                    }));
    	                }
    	            }
    	        }
    	    );
        };

    Now we are planning to make the method _productModel.getAllProductsAutoComplete an asynchronous one. So it will not return the result anymore instead it will fire a call back method when the result is ready.
    Is there any way to use such asynchronous method call in data adapter?

    Thanks in advance,
    Jitto P.Jose


    Peter Stoev
    Keymaster

    Hi jittopjose,

    When you set the “url” property of the source object instead of setting localdata, the plugin will make Ajax call to the url. Please, look at the jqxDataAdapter’s help page – http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdataadapter/jquery-data-adapter.htm

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    jittopjose
    Participant

    Thanks for the replay.
    In fact the method I am calling is not a remote method. so cannot give URL. its a local method to access web sql in node-webkit. the database access in asynchronous. so the result come only in call back.. is it possible to give local method name for url field?


    Peter Stoev
    Keymaster

    Hi jittopjose,

    If it is local, it is not using Ajax. No, it is not possible to give method name instead of url.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    jittopjose
    Participant

    I manged to make it work in a different way. It may not be an optimized way. but it works. the code is as follows:

    self.productSource = function (query, response) {
    	    var dataAdapter = new $.jqx.dataAdapter
    	    (
    	        {
    	            localdata: getAllProductsAutoCompleteData(query, response),
                    datatype: "array"
    	        },
    	        {
    	            autoBind: true,
    	            formatData: function (data) {
    	                data.name_startsWith = query;
    	                return data;
    	            }
    	        }
    	    );
        };
    
        function getAllProductsAutoCompleteData(query, response){
        	_productModel.getAllProductsAutoComplete(query, function(data){
    	            	if (data.length > 0) {
    	                    response($.map(data, function (item) {
    	                        return {
    	                            label: item.ProductName,
    	                            value: item.ProductName
    	                        }
    	                    }));
    	                }
    	            });
        	return [];
        }

    now the asynchronous method call works and auto complete values are coming properly to the jqxInput

    Thanks,
    Jitto P.Jose

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.