views:

804

answers:

1

I am trying to add a delete button to the Dojo Datagrid and I currently have the following javascript:

  function createGrid() {
         gridTmp = new dojox.grid.DataGrid({
                 store: jsonStore,
                 structure: [ 
           {name: "Report No", field:"inc_number"},
        {name: "Incident Date", field: "IncidentDate"},
        {name: "Report Date", field: "reportDate"},
     {name: "Location", field: "location"},
     {name: "Delete", field: "inc_number", formatter: getDelete}
     ],
                 noDataMessage: 'No results returned'
         }, "grids");

         return gridTmp;
  }
  dojo.addOnLoad(function() {
         grid = createGrid();
         grid.startup();
  });

function getDelete(item) { return "<button onclick=\"location.href='/report?command=delete&reportNo=" + store.getIdentity(item) + "'\">Delete</button>"; }

Whenever I load the page I only get an empty grid with a message "sorry an error occurred." If I remove the last field with the "getDelete" formatter, the datagrid populates just fine. I am not sure what I am doing wrong so any help would be appreciated.

+1  A: 

You made several errors in your getDelete function:

  1. store is not defined, probably you meant jsonStore
  2. item is not object from you store. It is property, specified by "field" (inc_number)

I think this will work for you:

function getDelete(item) {
  return "<button onclick=\"location.href='/report?command=delete&reportNo=" + item + "'\">Delete</button>";
}
ivalkeen
Thank you so much for the help, your code worked perfectly. Yeah, still trying to get the hang of dojo and javascript. Thanks again
Avanst