Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding button to dojo datagrid

Tags:

dojo

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.

like image 823
Avanst Avatar asked Nov 10 '09 13:11

Avanst


1 Answers

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>";
}
like image 113
ivalkeen Avatar answered Sep 20 '22 07:09

ivalkeen