Announcement

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

    ListGrid.exportData() returns "Error: server returned invalid JSON response"

    SmartClient Version: v11.0p_2016-05-14/LGPL Development Only (built 2016-05-14)
    Browser: Chrome, IE... doesn't seem to matter
    Reference: http://www.smartclient.com/#export


    What I'm trying to do: Use ListGrid.exportData() to download a csv representation of the grid.

    What I've done:
    1. Coded my server (.NET) to create a csv and return it as an attachment when the request is made. This seems to be working as I can see the response in Fiddler and it looks right, including the headers.
    2. Created the following function and hooked it up to a button click.

    Code:
    function ExportGrid(grid) {   
        grid.exportData({
            exportAs: "csv"
            , exportDisplay: "download" 
            , lineBreakStyle: "dos"
            , exportToClient: false // needed for callback to work?        
        }, function (dsResponse, data, dsRequest) {
            isc.say("Got response");
        });
    }
    What happens: The request is sent and the server creates the appropriate response (I think). From the console, here is the request:
    Code:
    {
        dataSource:"fise_FiseLog", 
        operationType:"fetch", 
        data:"{\n    \"dataSource\":\"fise_FiseLog\", \n    \"operationType\":\"fetch\", \n    \"sortBy\":[\n        \"-FiseLogId\"\n    ], \n    \"textMatchStyle\":\"substring\", \n    \"data\":{\n    }, \n    \"oldValues\":null\n}", 
        sortBy:[
            "-FiseLogId"
        ], 
        textMatchStyle:"substring", 
        showPrompt:false, 
        requestId:"fise_FiseLog$6277", 
        fallbackToEval:false, 
        exportAs:"csv", 
        exportDisplay:"download", 
        lineBreakStyle:"dos", 
        exportToClient:false, 
        exportRawValues:true, 
        exportPropertyIdentifier:"name", 
        exportFilename:"Results.csv", 
        downloadResult:false, 
        downloadToNewWindow:false, 
        lastClientEventThreadCode:"MUP5", 
        bypassCache:true, 
        dataProtocol:"postMessage", 
        isRestRequest:true, 
        dataFormat:"json", 
        contentType:"application/json"
    }
    ... and here is part of the response:

    Code:
    "FiseLogId","358120","Source","YO00DBSD01","Interface","INFPC013","DateTime","5/20/2016 10:45:08 AM","LogSeverityId","5","Message","Status update: SSIS Package INFPC013_Create_FISCal_File set status to FILE_CREATED for interface file DGS_INFPC013_B7411_2016-05-20
    which is good csv.... and from Fiddler, the headers contain
    Code:
    Content-Disposition: attachment; filename=Result.csv
    which seems right.

    But the browser does not attempt to open or save the file. Instead, I get an isc warning dialog that says,
    Error: server returned invalid JSON response
    Obviously I don't want a JSON response and the server is not sending a JSON response. I want a csv attachement response which is what the server is returning but it seems like the grid is expecting a JSON response. The callback is never called.

    Questions:
    1. Is this supposed to work with LPGL? The showcase example indicates that Pro is required but makes it sound like that is only for a JSON response.
    2. If so, what am I doing wrong? How can I tell the grid not to expect a JSON response?

    Thanks








    #2
    The docs are correct, exportData() does not work with LGPL.

    You can make your own export by sending data to the server in a format of your choosing, and setting rpcRequest.downloadResult.

    Comment


      #3
      Ok, that's the road I was heading down. Since my server already knows how to interpret a request from a ListGrid (with paging, sorting, filtering etc.), is there a way to extract that request object from the ListGrid so that I can send it manually?

      Comment


        #4
        There isn't a way to obtain a request object in one call, but you can call getCriteria(), getSortSpecificiers(), etc, to put together the information you need for your request.

        Comment


          #5
          Oy! I was afraid of that. Ok, that's what I'll do then. Too bad cuz all the information is there and the ListGrid already knows how to make the request object (like it does when you get data) in the proper format that the server already knows how to process.

          Comment

          Working...
          X