views:

1244

answers:

1

Hi,

I am struggling with a simple dojo datagrid in my Zend Framework project.

I have a list of data from a mysql table that I can display, however I want users to be able to remove selected rows (and remove them from the db). I am using the example from Dojo DataGrid adding and deleting data. My code in my view for the datagrid looks like this.

<div dojoType="dojo.data.ItemFileReadStore" jsId="skillstore" url="<?php echo $this->baseUrl()?>/skills/hist/<?php echo $this->histid;?>"></div>

<table id="skillgrid" jsId="skills" dojoType="dojox.grid.DataGrid" store="skillstore"   style="height:300px;width:500px;">
 <thead>
 <tr>
  <th field="skillid" hidden="true"></th>
  <th width="auto" field="skill">Skills</th>
 </tr>

</thead>
</table>
<div>
<button dojoType="dijit.form.Button" onclick="removeRows()" >Remove Selected Row</button>
<button dojoType="dijit.form.Button" onclick="addRow()">Add another skill</button>
</div>

I've placed the code for the removing of the rows inbetween the view scripts captureStart and captureEnd tags. The code for the removeRows() looks like this.

function removeRows(e){  
 var items = skillsgrid.selection.getSelected();

 if(items.length){

  dojo.forEach(items, function(selectedItem){

   if(selectedItem !== null){

    skillstore.deleteItem(selectedItem);
   }//endif
  });//end foreach

 }//end if
}

The main problem I get is that when I select a row and click the button, firebugs complains that skillstore.deleteItem is not a function. I have yet to try and remove the entry from the database.

Any pointers would be much appreciated.

A: 

I think all you have to do is use the jsId attribute value as ID instead of the id one:

var items = skills.selection.getSelected();

EDIT:

If that doesn't work, did you add the following right after the closing body tag?

<script type="text/javascript" src="dojo.js" djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
    dojo.require("dojox.grid.DataGrid");
    dojo.require("dojo.data.ItemFileWriteStore");
    dojo.require("dijit.form.Button");
</script>

EDIT2:

Actually, you are using a read-only store, that is the problem.

Franz
sadly I still get the same error about selectedItem.deleteItem is not a function??
Grant Collins
Edited it again, this should be the real answer...
Franz
Thanks for this however I now have a different error message now of dojo.data.ItemFileReadStore: invalid item argument, in the dojo.js file. I've checked my code to ensure that the all references for the grid is using the ItemFileWriteStore. Any Ideas?
Grant Collins
Does this help (especially the first answer)? http://www.dojotoolkit.org/forum/dojox-dojox/dojox-grid-support/dojo-data-itemfilereadstore-invalid-item-argument-when-deleting
Franz
Yes, thank you for all your help
Grant Collins