PDA

View Full Version : Accessing a column in a JSONStore that is not displayed in a Grid.



dduffy
13 Jul 2010, 11:37 PM
Hi All,

I have a JsonStore containing several 8 columns. I display 7 of these columns in a grid, but I do no want to display the eight column as it is simply a primary key, I know in the grid you can set the hideable column to true, but this will allow the user to view the column - it is an OK solution but not the one i want.

I want to be able to reference back to the JsonStore when the user doubleclicks the row in the Grid. My set up is as follows


var recordFields = [
{name: "first_name", mapping: "first_name" },
{name: "last_name", mapping: "last_name" },
{name: "employee_id", mapping: "employee_id" },
{name: "time_code_description", mapping: "time_code_description" },
{name: "cost_centre_description", mapping: "cost_centre_description" },
{name: "attendance_date", mapping: "attendance_date" },
{name: "attendance_hours", mapping: "attendance_hours" },
{name: "attendance_date_raw", mapping: "attendance_date_raw" }

];

var remoteJsonStore;
remoteJsonStore = new Ext.data.JsonStore( { fields : recordFields,
url :"cp_attendance_enquiry.ajax_get_data",
totalProperty : "totalCount",
root : "records",
id : "ourRemoteStore",
autoload : false,
remoteSort : true ,
baseParams : {p_employee_no: "", p_attendance_type: "", p_cost_centre:""},
paramNames: { start: "p_start", limit: "p_limit"}
} );

var columnModel;
columnModel = new Ext.grid.ColumnModel( [
{
header : "Staff Number",
dataIndex : "employee_id",
sortable : false,
width : 50,
resizable : false,
hidden : true
},
{
header : "Last Name",
dataIndex : "last_name",
sortable : true,
hideable : false,
width : 120
},
{
header : "First Name",
dataIndex : "first_name",
sortable : true,
hideable : false,
width : 120
} ....... etc.....

var grid = new Ext.grid.GridPanel({
height: 300,
width: 900,
colModel: columnModel,
store: remoteJsonStore,
loadMask: true,
title: "Attendance Record Detail",
viewConfig: {
forceFit: true,
emptyText: "No data available to display...."
}
});

grid.on("rowdblclick", function(grid, rowIndex, e) {
var cell_value = grid.getSelectionModel().getSelected();
var cells_value = cell_value.get("employee_id");
Ext.get("p_personnel_no").set({value: cells_value});
//alert(remoteJsonStore.query("employee_id",cells_value).getCount());
cp_show_attendance_screen();
});


So when the user doublclicks the row the grid.on("rowdblclick"....) function executes, how can I reference back to the JsonStore for this exact row? Is there some link indiex between a JsonStore and the column it is mapped too?
Or should I be doing this differently?

Much appreciated
Darragh.

dduffy
14 Jul 2010, 12:02 AM
Hi All,

I have a JsonStore containing several 8 columns. I display 7 of these columns in a grid, but I do no want to display the eight column as it is simply a primary key, I know in the grid you can set the hideable column to true, but this will allow the user to view the column - it is an OK solution but not the one i want.

I want to be able to reference back to the JsonStore when the user doubleclicks the row in the Grid. My set up is as follows


var recordFields = [
{name: "first_name", mapping: "first_name" },
{name: "last_name", mapping: "last_name" },
{name: "employee_id", mapping: "employee_id" },
{name: "time_code_description", mapping: "time_code_description" },
{name: "cost_centre_description", mapping: "cost_centre_description" },
{name: "attendance_date", mapping: "attendance_date" },
{name: "attendance_hours", mapping: "attendance_hours" },
{name: "attendance_date_raw", mapping: "attendance_date_raw" }

];

var remoteJsonStore;
remoteJsonStore = new Ext.data.JsonStore( { fields : recordFields,
url :"cp_attendance_enquiry.ajax_get_data",
totalProperty : "totalCount",
root : "records",
id : "ourRemoteStore",
autoload : false,
remoteSort : true ,
baseParams : {p_employee_no: "", p_attendance_type: "", p_cost_centre:""},
paramNames: { start: "p_start", limit: "p_limit"}
} );

var columnModel;
columnModel = new Ext.grid.ColumnModel( [
{
header : "Staff Number",
dataIndex : "employee_id",
sortable : false,
width : 50,
resizable : false,
hidden : true
},
{
header : "Last Name",
dataIndex : "last_name",
sortable : true,
hideable : false,
width : 120
},
{
header : "First Name",
dataIndex : "first_name",
sortable : true,
hideable : false,
width : 120
} ....... etc.....

var grid = new Ext.grid.GridPanel({
height: 300,
width: 900,
colModel: columnModel,
store: remoteJsonStore,
loadMask: true,
title: "Attendance Record Detail",
viewConfig: {
forceFit: true,
emptyText: "No data available to display...."
}
});

grid.on("rowdblclick", function(grid, rowIndex, e) {
var cell_value = grid.getSelectionModel().getSelected();
var cells_value = cell_value.get("employee_id");
Ext.get("p_personnel_no").set({value: cells_value});
//alert(remoteJsonStore.query("employee_id",cells_value).getCount());
cp_show_attendance_screen();
});


So when the user doublclicks the row the grid.on("rowdblclick"....) function executes, how can I reference back to the JsonStore for this exact row? Is there some link indiex between a JsonStore and the column it is mapped too?
Or should I be doing this differently?

Much appreciated
Darragh.

dduffy
14 Jul 2010, 12:53 AM
Ok I found a solution:

//query my primary ID will return one record.
mc = remoteJsonStore.query("primaryID",key_id).itemAt(0);
//then object returned you can access the JSON varaiables as follows.
alert(mc.json.attendance_date_raw);

Darragh

Animal
14 Jul 2010, 1:03 AM
This is in the FAQ

dduffy
14 Jul 2010, 8:09 AM
thanks animal, had a look through the FAQ but did not see this, can you point me in the direction of where this is?

Animal
14 Jul 2010, 9:32 AM
http://www.sencha.com/learn/Ext_FAQ_Grid#Add_click_handlers_to_specific_grid_cells

dduffy
14 Jul 2010, 11:05 PM
Excellent thanks Animal, so an another solution is
grid.on("rowdblclick", function(grid, rowIndex, e) {
var record = grid.getStore().getAt(rowIndex);
alert(record.json.attendance_date_raw); // or what ever your column is called.
});
thanks again Animal for pointing me in the right direction.,
Darragh.