Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Filter the DataSource dataURL

    Is there any way to filter the dataURL result in smatClient because i need to do it on the client side

    typo3 response - JSON wrapped in the <div> tags (cant remove the tags and divs in typo3 so i need to filter it on the client side)
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    	<!--
    
    		BEGIN: Content of extension "api_typo3plugin", plugin "tx_typo3plugin_pi4"
    
    	-->
    	<div class="tx-apidashboard-pi4">
    		[ { ...JSON... } ]
    	</div>
    	
    	<!-- END: Content of extension "api_typo3plugin", plugin "tx_typo3plugin_pi4" -->
    so i need to remove the comments and get the JSON ([ { ...JSON... } ])


    I wrote this code:

    Code:
    isc.DataSource.create({
            ID:"xx",
    	dataFormat:"custom",  // not json /xml -must be custom !!
    	dataURL:"http://mysite.com/source.json",
    	transformResponse: function(dsResponse, dsRequest, data){
    		var test = dsResponse.data;
    
                    // get only JSON from, the response
    		var atpos = test.indexOf("[");
                    var atpos2 = test.indexOf("]");
    		
    		if (atpos > -1) {
    			test = test.substring(atpos,atpos2+1);
    		}
    
    	         dsResponse.data =test;
                     data =test;
    
                    this.dataFormat="json";                                                        //set dataformat back to json
                    dsResponse.data =   JSON.parse(dsResponse.data);
    
                    return dsResponse;
             }
    ok i filter out the string at the beginning of the Response but can't transform it back to json :|

    it returns something but it's not correcly formated - the Loading data... disapears but the grid is empty (how to debug it ???)


    (when i call the json source file without the comments and divs(remove it manually) with dataFormat: "json" - it works )


    source json:
    Code:
    [ {"nmr":"022242069","nmr2":"122638958","price":"0.06","code":null,"time":"01.01.2011 14:08:17","duration":"18"},{"nmr":"062244233","nmr2":"112638958","price":"0.04","code":null,"time":"01.01.2011 21:01:53","duration":"14"} ]
    Last edited by Cruonit; 14 Feb 2011, 14:19.

    #2
    lol it works :D

    Code:
    	transformResponse: function(dsResponse, dsRequest, data){
    		var test = dsResponse.data;
    		var atpos = test.indexOf("[");
    
    		if (atpos > -1) {
    			test = test.substring(atpos);
    		}
    		
    		this.dataFormat="json";
    		
    		dsResponse.data = JSON.parse(test);
    		
    		data = test;
    		dsResponse.totalRows =dsResponse.data.length;
    		
    		return this.Super("transformResponse", [dsResponse, dsRequest, data] );
    	},

    just added the
    dsResponse.totalRows =dsResponse.data.length;
    Last edited by Cruonit; 14 Feb 2011, 14:51.

    Comment

    Working...
    X