Question

I'm trying to connect a dojo dgrid to a solr data service and need some help. When I use jsonp I can get connected to the solr data and output the data result to the screen with something like this: dojo.require("dojo.io.script"); function searchGoogle(){ // Look up the node we'll stick the text under. var targetNode = dojo.byId("output");

       // The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
       var jsonpArgs = {
         url: "myExternalSolrURL",
         callbackParamName: "json.wrf",
         content: {
           wt: "json",
           rows: "12",
           start: "1",
           q: "*"
         },
         load: function(data){
           // Set the data from the search into the viewbox in nicely formatted JSON
           targetNode.innerHTML = "<pre>" + dojo.toJson(data, true) + "</pre>";
         },
         error: function(error){
           targetNode.innerHTML = "An unexpected error occurred: " + error;
         }
       };
       dojo.io.script.get(jsonpArgs);
     }
     dojo.ready(searchGoogle);

But, when I try to use jsonrest to connect to the solr data and get it to show up in a dgrid nothing appears to happen. This is the code I have for that:

<script>
    var myStore, dataStore, grid;
    require([
    "dojo/store/JsonRest",
    "dojo/store/Memory",
    "dojo/store/Cache",
    "dgrid/Grid",
    "dojo/data/ObjectStore",
    "dojo/query",
    "dijit/form/Button",
    "dojo/domReady!"
    ], function (JsonRest, Memory, Cache, Grid, ObjectStore, query, Button, domReady) {
        myStore = Cache(JsonRest({
            target: "myExternalSolrURL", 
            idProperty: "id" 
            }), 
            Memory({ idProperty: "id" }));
        grid = new Grid({
            store: dataStore = ObjectStore({ objectStore: myStore }),
            structure: [
    { name: "Thing id", field: "id", width: "50px" },
    { name: "Name", field: "name", width: "200px" },
    { name: "detail", field: "detail", width: "200px" }
    ]
        }, "grid"); // make sure you have a target HTML element with this id
        grid.startup();
    });
</script>

<div style="height: 300px; width: 600px; margin: 10px;">
    <div id="grid">
    </div>
</div>

Does anyone see what I am missing?

Was it helpful?

Solution 2

Apparently part of the problem is that a Solr index is not a flat data structure like a grid or dgrid can deal with. When you have nested data returned like a Solr or ElasticSearch index will return it must be "flattened" to go into a grid. However, this sort of hierarchy of data will work with a tree vs a grid. So the next challenge is to connect to the index and flatten it.

OTHER TIPS

  1. You changed your code to use dgrid, but it looks like you are still attempting to use a dojo/data store with dgrid. dgrid only supports the dojo/store API, so stop wrapping your store in ObjectStore.
  2. dgrid/List and dgrid/Grid do not contain store logic. You will want to either use dgrid/OnDemandGrid or mix in dgrid/extensions/Pagination.
  3. Make sure the service you are using with dojo/store/JsonRest actually behaves as the store implementation expects (or use or write a diffrent dojo/store implementation)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top