Peter Della-Nebbia
Peter Della-Nebbia

Reputation: 827

How to return values of an editable column in a Dojo DataGrid on an XPage?

I have an editable Priority column in a Dojo DataGrid. Prior to saving the user's changes I want to verify that for the handful of entries in the grid, the user has not set the value for the Priority field to the same value. That is, in the case where they set the Priority column to [1,2,3,3,5] for the five rows in the grid I want to raise an alert reminding them that the Priority column needs unique values.

The following is my code for the xe:viewItemFileService for the grid:

<xe:restService id="restService1" jsId="restServiceObj"
        pathInfo="pathinfo">
        <xe:this.service>
            <xe:viewItemFileService defaultColumns="true"
                contentType="application/json" viewName="DocsByUsername"
                var="rsEntry" sortColumn="Priority"
                keys="#{sessionScope.username}">
            </xe:viewItemFileService>
        </xe:this.service>
    </xe:restService>  

The following is the markup for my Dojo DataGrid with the editable Priority column:

    <xe:djxDataGrid id="djxDataGrid1" singleClickEdit="true"
        jsId="gridObj" storeComponentId="restService1" rowSelector="20px">
        <xe:djxDataGridColumn id="djxDataGridColumn1" field="UserName"
            label="UserName" width="100px">
        </xe:djxDataGridColumn>
        <xe:djxDataGridColumn id="djxDataGridColumn2" field="Field1"
            label="Field1" width="100px">
        </xe:djxDataGridColumn>
        <xe:djxDataGridColumn id="djxDataGridColumn3" field="FieldN"
            label="FieldN" width="100px" editable="true">
        </xe:djxDataGridColumn>
        <xe:djxDataGridColumn id="djxDataGridColumn4"
            field="Priority" label="Priority" width="100px" editable="true"
            cellType="dojox.grid.cells.Select">
            <xe:this.options><![CDATA[#{javascript:var choices = ["1","2","3","4","5"];
                                 return choices;}]]></xe:this.options>
        </xe:djxDataGridColumn>
    </xe:djxDataGrid>

I call the following priorirityArray() function when the user presses the SAVE button ....

<xp:scriptBlock id="scriptBlock3">
<xp:this.value><![CDATA[
function priorityArray(){
var rsStore = restServiceObj;
var grid = gridObj;

var rows = 0 ;
var priorities = [];
var item;
var unid;
var priority;

    var actualRows = restServiceObj['_items'].length;

    for(var i = 0 ; i < actualRows ; i++){
      item  = grid.getItem(i);
      if(item != null){
        unid = item["@unid"];
        priority = item["Priority"];
        priorities.push(item["Priority"]);
        rows = i;
     }
    };

   return priorities;

   };]]></xp:this.value>
</xp:scriptBlock>

My problem is in the for loop. The item object is being returned for ear row in the grid, but my item["fieldName"] calls are returning nothing. I have used this notation in the past in the onRowClick event where I pass in the rowIndex for the arguments[0] object but it does not work in the script block in my for loop to return all the entries.

BTW, I'm not married to this looping approach so if there is an easier way to return all the current in-memory field/column values from the the gridObj or restServiceObj I am all ears.

Upvotes: 2

Views: 512

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30970

DataGrid row item's values are stored in an object attributes within item.

enter image description here

Change your code to

    unid = item.attributes["@unid"];
    priority = item.attributes["Priority"];
    priorities.push(priority);

Upvotes: 3

Related Questions