Search code examples
jsondojodojox.grid.datagriddojox.grid

Getting Error While creating DOJOX enchanced grid programmatically


I am getting "Sorry, an error occurred". While rending a Enhanced grid which I have created.

The JSON Object is set in the requestattribute "dataitems" which I am trying to render

{"items":[{"prinId":"0280","subClientId":"5187","clientId":"9006","sysId":"3759"}],"label":"userId","identifier":"requestId"}

The Dojo Code is below

<script>dojoConfig = {async: true, parseOnLoad: true}</script>
    <script>
    require([
    "dojo/_base/lang", 
    "dojox/grid/EnhancedGrid",  
    "dojo/data/ItemFileWriteStore", 
    "dojo/dom","dojox/grid/cells", 
    "dojox/grid/enhanced/plugins/Pagination", 
    "dojox/grid/enhanced/plugins/NestedSorting",
    "dojo/on",
    "dojo/_base/event",
    "dojo/parser",
    "dojo/_base/array",
    "dojo/dom",
    "dojox/grid/enhanced/plugins/IndirectSelection",
    "dijit/Dialog",
    "dijit/form/Form",
    "dijit/form/TextBox",
    "dijit/form/DateTextBox",
     "dojo/domReady!"],


      function(lang, EnhancedGrid, ItemFileWriteStore, dom,gridCells,Pagination,NestedSorting,on,event,parser,array,dom,IndirectSelection,Dialog,Form){
   var store=new dojo.data.ItemFileReadStore({data: <%=request.getAttribute("dataItems")%>});


   var layout = [{name: 'Client Bank Id', field: 'clientId', width: '130px'},
                    {name: 'Sub Client Bank Id', field: 'subClientId', width: '130px'},
                    {name: 'Sys Id', field: 'sysId', width: '130px'},
                    {name: 'Prin Id', field: 'prinId', width: '220px'}];
            /*create a new grid*/
      var grid = new dojox.grid.EnhancedGrid({
          id: 'grid',
          store: store,
          structure: layout,


           plugins: {
           nestedSorting: true

          /*  pagination: {
                pageSizes: ["25", "50", "100", "All"],
                description: true,
                sizeSwitch: true,
                pageStepper: true,
                gotoButton: true,
                maxPageStep: 3,                            
                position: "bottom"
            }  */
          }


          },document.createElement('div'));
          /*append the new grid to the div*/

   dojo.byId("gridDiv").appendChild(grid.domNode);
   grid.startup();





   });

    </script>

Solution

  • Hmmm, it's your store definition, specifically the value for identifier. This needs to be one of the element names. Try something like the following store object:

    var store = new dojo.data.ItemFileReadStore({
      data: {
        "items":[
          {"prinId":"0280", "subClientId":"5187", "clientId":"9006", "sysId":"3759" }
        ],
        "label":"clientId",
        "identifier":"clientId"
      }
    });