Link to home
Create AccountLog in
Avatar of jgcoffey
jgcoffey

asked on

How do I implement a Select All check box for Dojo v1.4.3 AdvancedDataGrid

I need to add a select all check box to the DataGrid checkbox column and code to programmatically check the boxes in the following jsp code

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1" session="true"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<link rel="stylesheet" type="text/css"
 href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css" />
<link rel="stylesheet" type="text/css"
 href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojox/grid/resources/Grid.css" />
<link rel="stylesheet" type="text/css"
 href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojox/grid/resources/claroGrid.css" />
<portlet:defineObjects/>
<script language="javascript" data-dojo-config="isDebug: true,parseOnLoad: true">

      dojo.require("dojox.grid.DataGrid");
      dojo.require("dojo.data.ItemFileWriteStore");
      dojo.require("dojox.grid.EnhancedGrid");
      dojo.require("dojox.grid.enhanced.plugins.IndirectSelection");
      dojo.require("dijit.form.Button");
      dojo.ready(init);

      var addPoliciesGrid;
      var addPoliciesStore;

      // set the layout structure:
      var addPoliciesLayout = [
      {
            field : 'policyNumber',
            name : 'Policy #',
            width : '70px'
      }, {
            field : 'billing',
            name : 'Billing',
            width : '90px'
      }, {
            field : 'owner',
            name : 'Owner',
            width : '80px'
      }, {
            field : 'insured',
            name : 'Insured',
            width : '80px'
      }, {
            field : 'paidTo',
            name : 'Paid to',
            width : '70px'
      }, {
            field : 'amount',
            name : 'Amount',
            width : '70px'
      } ];
      
      function init() {
            initalizeAddPoliciesStore();
      }
      
      function initalizeAddPoliciesStore() {      
            addPoliciesStore = new dojo.data.ItemFileWriteStore(
                        {
                              url : "http://localhost:10039/ProduceJSONWeb/servlet/com.mycompany.servlet.ReturnJson"
                        });

            addPoliciesGrid = new dojox.grid.EnhancedGrid({
                  id : 'addPoliciesGrid',
                  plugins: {indirectSelection: true},
                  query : {
                        policyNumber : '*'
                  },
                  store : addPoliciesStore,
                  structure : addPoliciesLayout
            }, 'addPoliciesGridTableId');

            addPoliciesGrid.startup();            
      }
      
      function displayAllCheckedPolicyNumber(){
      addPoliciesGrid.store.fetch({
          onComplete: function (items) {
               dojo.forEach(items, function (item, rowIndex){
                           if(addPoliciesGrid.selection.selected[rowIndex]){
                                 console.debug("rowIndex = "+rowIndex + " Policy # = "+item.policyNumber);
                           }
                     });
                     }                     
            });
      }
      
//http://dojotoolkit.org/reference-guide/dojox/grid/EnhancedGrid.html#dojox-grid-enhancedgrid
</script>

<div id="addPolicies" style="height:200px">
      <table id="addPoliciesGridTableId" dojotype="dojox.grid.DataGrid"></table>
</div>
<div id="showSelectedButton">
      <button onClick="displayAllCheckedPolicyNumber()">Show all checked Policy#</button>
</div>
ASKER CERTIFIED SOLUTION
Avatar of NetExpert-Warszawa
NetExpert-Warszawa
Flag of Poland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jgcoffey
jgcoffey

ASKER

This code solves the problem with selecting the check boxes and I tested it by adding a button to my display however my complete requirement call for adding a "check all" check box implemented on the header row of the check box column of the advancedgrid. "I need to add a select all check box to the DataGrid checkbox column.." If you can show me how to do this then I will accept the solution. Thank you.
The solution did not completely solve my problem but it looks like the solution I require is not going to delivered to me. It seems like Experts Exchange does not recognize Dojo as a zone so it is difficult to find the target audience I require to answer this solution. I currently regret that I paid a full year subscription
to this service based on another users recommendation.