Utilizing Solr and JsonRest to populate a custom Dojo widget on the OnDemandGrid

Incorporating a custom Dojo widget into my OnDemandGrid is proving to be quite the challenge. Each widget's data is sourced from a Solr query, and with potentially thousands of search results expected, I've turned to JsonRest for querying and pagination management. Here's my current setup:

The store:

var store = new JsonRest ({
    target: "/solr/json/response",
});

Setting up the grid:

var grid = new (declare([OnDemandGrid, Pagination])) ({
    store: store,
    getBeforePut: false,
    columns: [
        {
             label: "Test",
             field: "first",
             renderCell: myRenderFunction //Custom widget rendering function
        }
    ]
}, "grid");

grid.startup();

myRenderFunction:

var myRenderFunction = function(object, data, cell) {

    var widget = new MyCustomWidget({
        doc: object,
        foo: bar
    }, cell.appendChild(document.createElement("div"));

    widget.startup();
    return widget;
}

A snippet of the Solr response in JSON format:

{
    "response":{
        "docs":[
            {
                "foo": "Hello",
                "bar": "World"
            },
            {
                "foo": "Easy as",
                "bar": "ABC"
            },
            {
                "foo": "Simple as",
                "bar": "Do re mi"
            }
        ]
    },
    "highlighting": { ... },
    "numFound": "74",
    "start": 0
}

Despite following tutorials successfully, attempting to render the widget onto the grid results in nothing appearing and gives a

TypeError: transform(...) is null
. What could be causing this issue?

Why won't my custom widget show up on the grid?

Answer №1

Encountering the same issue when trying to integrate Solr results with dgrid and JsonRest.
JsonRest utilizes QueryResults as a wrapper for its output.
The challenge lies in QueryResults only accepting arrays or promises, while an object is currently being provided.

To pass the docs array to QueryResults, consider creating a custom JsonRest store like this:

define([
    "dojo/Deferred", "dojo/io-query", "dojo/_base/declare", "dojo/request/xhr",
    "dojo/store/JsonRest", "dojo/store/util/QueryResults"
], function (Deferred, ioQuery, declare, xhr, JsonRest, QueryResults) {
    return declare([JsonRest], {
        target: '/solr/json/response',
        idProperty: 'foo',
        query: function (query, options) {
            var results, total, count = options.count, start = options.start;
            if (start > 0 || count >= 0) {
                query.start = start;
                query.rows = ((options.hasOwnProperty('count') &&
                    count !== Infinity) ? count : 25);
            } else {
                console.error('Missing start and count arguments');
                return;
            }
            results = new Deferred();
            results.total = new Deferred();
            xhr(this.target, {
                query: ioQuery.objectToQuery(query),
                handleAs: 'json',
                headers: {
                    Accept: this.accepts
                }
            }).then(function (data) {
                total = data.response.numFound;
                results.total.resolve(total);
                results.resolve(data.response.docs);
            }, function (e) {
                console.error(e.response.status + '. ' + e.message);
            });
            return new QueryResults(results);
        }
    });
});

A suggestion would be to defer using a custom renderCell function until after successfully populating dgrid.

edit: Note that OnDemandGrid does not work with the Pagination extension.
Decide whether you prefer discrete paging controls or infinite scroll managed by dgrid.
Refer to Pagination and OnDemand documentation for more information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble getting CSS absolute and relative positioning to work with my div slider carousel

I'm currently working on creating a slider carousel using VUE, where the CSS classes (3 divs) are looped through. However, I am facing an issue where every time a div fades out, the next slider creates a duplicate slider at the bottom, resulting in tw ...

Is there a way to compel a react component to refresh from a separate JavaScript file?

I'm facing an issue where a React component is not displaying a list of items fetched from the backend using websockets. Since my websockets.js file is outside of the React hierarchy, the list never gets refreshed and therefore the items are not shown ...

Tips for increasing a numerical value with jQuery within a footnote extension for redactor.js

Currently, I am in the process of developing a plugin for redactor.js that will enable users to include footnotes. The end goal is to have these footnotes stored in a separate table in the database; however, as of now, it's just a mockup for a larger ...

Elaborate on the specific error message within the .error() jQuery function

Currently, I am utilizing .error() as the callback for .post(). Here is an example of how I am using it: $.post("url", function(data){}) .error(function(){ alert("some error"); }); If an error occurs, I would like to display a detailed error ...

Deciphering a gzip encoded JSON with Lotus-Script

When using Lotus Script, I am encountering difficulty decoding gzip encoded JSON content from an HTTP request. Set webRequest = Session.createhttprequest() Call webRequest.Setheaderfield("cache-control", "no-cache") Call webRequest.Setheaderfiel ...

Distinguishing between selecting rows and selecting checkboxes in Mui Data Grid

Is there a way to differentiate between clicking on a row and clicking on the checkboxes? I want to be able to select multiple rows by clicking anywhere in the row except for the checkbox column. When clicking outside the checkbox column, I would like to p ...

Potential performance concerns and side effects of passing a parent component as a prop to its children in React and Redux

As I review code in a React-Redux project, I've noticed a recurring pattern where a parent smart component is being passed as a prop to its child component: import React from 'react'; import Child from '../components/Child'; expo ...

Obtain the value in jquery format

Having an HTML element structured like this: <td id="length" data-length=<?php echo $length;?> > I am trying to retrieve the value of my PHP variable ($length) using a jQuery script. Next, I need to format it by replacing commas with period ...

A simple guide on accessing a local PDF file and returning it as the response for an ExpressJS application

In my ExpressJS application, I have a method for generating a PDF file and sending it to the client. However, there are cases where I need to retrieve an existing local PDF file and return it as the response. I'm unsure how to handle this scenario. ...

What is the best way to create a Promise that is fulfilled when an event is emitted by an event emitter in JavaScript or Node.js?

Is there a way to create a Promise in Node JS that will only resolve when a specific event is emitted by an event emitter? I am trying out the following code snippet, but I am unsure how to make the promise wait until the event occurs. function bar(resol ...

Tips on serializing a SortedDictionaty with a unique IComparer implementation

The objective is clear: arrange the dictionary serialization in descending order by key. [HttpGet] [Route("")] public IActionResult Test() { var dic = new SortedDictionary<int, string>(new DescComparer<int>()) {{1, "A& ...

IE9 is causing a bizarre problem where the entire page is suddenly jumping. It's

UPDATE: The client has requested testing to disable the click and drag feature in IE, so replicating the bug may be difficult at this time. I apologize if this hinders the community's ability to help fix the root issue. Here's the issue: It occu ...

What is the best way to center text on an HTML canvas?

Is it possible to center an h1 tag in the middle of an HTML canvas using either JavaScript or HTML? I already have a CSS file for canvas styles. HTML <body> <canvas id="myCanvas"></canvas> <script src="canvas.js"></scri ...

Unraveling multi-layered Json structures in SQL Server

I managed to extract JSON data from an API and part of the JSON file can be seen below. My goal was to parse the JSON information and store it in a SQL table. However, when I attempted to execute the SQL query provided, only one row was returned. How can I ...

Posting data to an HTML file with a foreign key matching the input value in Express.js

My discussion platform features topics and comments. Each comment has its own unique topic_id. Currently, I am able to post comments for the initial topic, but encountering issues when adding new comments for other topics. I am looking for guidance on effi ...

Tips on sharing global variables in Express 4.*

If I have a variable called data = {} stored in a file named data.js; When I import this file into another page, I only receive the value of the variable. How can I obtain its reference instead? By reference, I mean that if I make any changes in the impo ...

Using PHP to extract all occurrences of window.location from an HTML document using regex

Is there a way to extract all the window.location instances in PHP? I have a list of URLs that I am fetching using cURL, saving the HTML content as a string, and now I need to identify and display all the occurrences of window.location separately. I atte ...

Having trouble selecting a default option in a dynamically populated select dropdown using ng-model in the dropdown

For my Angularjs application, I needed to dynamically return a select drop down with its selected option. To accomplish this, I implemented the following function: function getCellRendererMapping(data) { if (data.order == 6) { return funct ...

transferring a document using axios, bypassing the FormData interface

One way to upload a file to the server is by using axios along with the FormData api. Here's an example: persist(photo){ let data = new FormData(); data.append('photo', photo); axios.post(`/api/photos/${this.user ...

"Encountering an undefined error when trying to retrieve an

Reviewing My Code: <html> <header> <title>Checkup Date</title> <script type="text/javascript"> function datechange() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpReque ...