Not able to add checkboxes to last column in dojo enhanced grid - dojo

I am creating the dojo Grid as below and I am using the indirectSelection plugin for creating a checkbox, as below, but by default the checkboxes will come at the first column of the grid. How do I make it to come at the last column?
var grid = new dojox.grid.EnhancedGrid({
id: 'serialsGrid',
style: 'width:auto;height:250px;',
store: store,
structure: layout,
rowSelector: '20px',
plugins: {
indirectSelection: {name:'Requested',headerSelector:true, width:"40px", styles:"text-align: center;"},
pagination: {
pageSizes: ["25", "50", "100", "All"],
description: true,
sizeSwitch: true,
pageStepper: true,
gotoButton: true,
/*page step to be displayed*/
maxPageStep: 4,
/*position of the pagination bar*/
position: "bottom"
}
}
}, document.createElement('div'));
/*append the new grid to the div*/
//var temp=grid.domNode;
dojo.byId("serialsGridDiv").appendChild(grid.domNode);
/*Call startup() to render the grid*/
serialsGridCopy=grid;
grid.startup();
});

The plugin itself has no capabilities of doing so as far as I know so I started looking at the functions the EnhancedGrid itself has and stumbled upon the function moveColumn() in grid.layout.
The documentation itself (here) was not really usefull, but I used it to move every column one position ahead so that the first column would become the last one.
I also made a working JSFiddle to demonstrate which you can see here. The code that is moving the columns can be found at the bottom of the code:
for (var i = 1;i < grid.layout.cells.length;i++) {
grid.layout.moveColumn(1, 1, i, i-1, grid.layout);
}
What it does is the following: it moves every column starting from index 1, so that means all columns except the indirectSelection column one step ahead (i-1).

Related

AnyColumn option added as new column in Dojo enhanced grid view

I am working on dojo enhanced grid view. I am able to display the grid in UI. But AnyColumn option is added as new column.
Example:
Any help will be appreciated...
Here is the Code
var mygrid = new EnhancedGrid({
id: "grid",
store: gridStore, //Data store passed as input
structure: gridStructure, //Column structure passed as input
autoHeight: true,
autoWidth: true,
initialWidth: width,
canSort : true,
plugins: {
filter: {
//Filter operation
isServerSide: true,
disabledConditions : {"anycolumn" : ["equal","less","lessEqual","larger","largerEqual","contains","startsWith","endsWith","equalTo","notContains","notEqualTo","notStartsWith","notEndsWith"]},
setupFilterQuery: function(commands, request){
if(commands.filter && commands.enable){
//filter operation
}
}
}
}, dojo.byId("mydatagrid"));
mygrid.startup();
Thanks,
Lishanth
First, do not use EnhancedGrid, instead use either dgrid or gridx.
I think by default anycolumn is added to the dropdown. If you want to remove then, I would suggest to
Register for click event on the filter definition
Iterate through the drop-down and remove the first entry which is anyColumn
or you can also try something like
dojo.forEach(this.yourgrid.pluginMgr.getPlugin('filter').filterDefDialog._cboxes, function(dropdownbox) {
dropdownbox._colSelect.removeOption(dropdownbox.options[0]);
});
Updated answer is. I know this is not the elegant way of doing it but it works.
//reason why I'm showing the dialog is that _cboxes of the filter are empty initially.
dijit.byId('grid').plugin('filter').filterDefDialog.showDialog();
dojo.forEach(dijit.byId('grid').pluginMgr.getPlugin('filter').filterDefDialog._cboxes, function(dropdownbox) {
var theSelect = dropdownbox._colSelect;
theSelect.removeOption(theSelect.options[0]);
});
//Closing the dialog after removing Any Column
dijit.byId('grid').plugin('filter').filterDefDialog.closeDialog();

Dojo Enhanced Grid with JSONREST issues

I'm trying to use a enhanced grid with Dojo JSONREST and i'm running into some issues.
I've been looking up some examples but can't figure out how to do what i need.
In the code below my rest service takes two parameters, and the query on the service works.
The problem is that when grid.startup() is called it seems to call the Rest service again, since there are no parameters passed the rest service falls over. What am i doing wrong here?
Also is there any way to update to the store so that is only contains the queried results?, so that when the grid appears it just contains these values?
Appreciate any help or pointers..
ready(function(){
var grid;
var store = new JsonRest({
target: "rest/search"
});
store.query({term: "test", category: "category"},
{
start: 10,
count: 10,
}).then(function(data){
// how do i update store with queried results?
});
dataStore = new ObjectStore({ objectStore: store });
/*set up layout*/
var layout = [[
{'name': 'Name', 'field': 'col1', noresize: true, 'width': '100%'},
]];
/*create a new grid:*/
grid = new EnhancedGrid({
id: 'grid',
store: dataStore,
structure: layout,
selectable: true,
selector: false,
selectionMode: 'none',
escapeHTMLInData: false,
autoHeight:true
}, document.createElement('div'));
grid.startup();
}
Have you tried setting the query parameter of the grid? A link to the docs. And a link to an example.
And by looking at the code in the question, it seems that the grid should display chunks/pages of data - an example using the pagination plugin for the grid.
The filter plugin might also be of interest to you.
when you define a new grid you have to pass it to dojo:
/*create a new grid:*/
grid = new EnhancedGrid({
id: 'grid',
store: dataStore,
structure: layout,
selectable: true,
selector: false,
selectionMode: 'none',
escapeHTMLInData: false,
autoHeight:true
}, document.createElement('div'));
/*append the new grid to the div*/
dojo.byId("gridDiv").appendChild(grid.domNode);
grid.startup();

when i move to next page in the dojo dataGrid, Rows are automatically got selected(the rows which are selected in first page)

In my dojo dataGrid if i select 7th and 8th rows for example in the first page and if i move to second page by using pagination feature. The rows(7th and 8th row which are selected in first page) are selected by default in the second page also.
Here is my grid:
var grid = new dojox.grid.EnhancedGrid({
id: 'linesGrid',
style: 'width:950px;height:250px;',
store: store,
structure: layout,
rowSelector: '20px',
plugins: {
indirectSelection: {headerSelector:true, width:"40px", styles:"text-align: center;"},
pagination: {
pageSizes: ["25", "50", "100", "All"],
description: true,
sizeSwitch: true,
pageStepper: true,
gotoButton: true,
/*page step to be displayed*/
maxPageStep: 4,
/*position of the pagination bar*/
position: "bottom"
}
}
}, document.createElement('div'));
Set the grid to keepSelection : true. This will maintain the proper rows selected.
You need to do a yourGrid.selection.deselectAll(); before showing the next page.
EDIT:
Part of this question was also discussed here:
not able to call a function on pagination dojo enhancedGrid

Paging is not working, using JsonRest with EnhancedGrid

I'm creating widget for IBM BusinessSpace, and I'm having some difficulties with paging.
Data are succesfully returned from database (using restlet) and displayed in a grid. Navigation is also displayed below the grid (next page, previous page, go to page, number of pages, etc).
If I, for example, have 3 pages, 5 rows per page, and want to navigate to second page, when I click on the page number 2, data reloads (it seems like restlet is called again), and first 5 rows (displayed on the first page) are showed on this one too. If I choose any other navigation option (next page, ...), same thing happeneds. Bottom line, every click results in first 5 rows from my database.
Any clue on how to resolve this issue?
Here's a code regarding this:
dojo.require("dojo.data.ObjectStore");
dojo.require("dojox.grid.enhanced.plugins.Pagination");
dojo.require("dojox.grid.EnhancedGrid");
dojo.require("dojo.store.JsonRest");
var restStore = new dojo.store.JsonRest({target:"https://localhost:9443/Application/hello"});
var dataStore = dojo.data.ObjectStore({objectStore: restStore});
dojo.ready(function(){
var grid = new dojox.grid.EnhancedGrid({
store: dataStore, <br>
structure: [
{name:"Value", field:"value", width: "auto"},
{name:"RequestID", field:"requestId", width: "auto"},
{name:"ID", field:"id", width: "auto"},
{name:"Name", field:"name", width: "auto"}
],
columnReordering: true,
clientSort: true,
rowSelector: '20px',
rowsPerPage: 5,
autoHeight: true,
plugins: {
pagination: {
pageSizes: ["5", "10", "15", "All"], // page length menu options
description: true, // display the current position
sizeSwitch: true, // display the page length menu
pageStepper: true, // display the page navigation choices
gotoButton: true, // go to page button
position: "bottom" // position of the pagination bar
}
}
}, "gridDiv");
grid.startup();
});
When using jsonRest in a grid, when you scroll the records not shown are not loaded yet, at this moment jsonRest makes a request for the data needed to show, for this pager to work as expected, in your rest implementation you have to consume a header that dojo creates (Range: 0-24), this one is sent by dojo so you know the offset and limit for the data needed, for the response, you have to return a header (Content-Range: items 0-24/66), the numbers tell dojo from where to where it should be showing and how much total record are.
This is an example in php (assuming that db and response are actual objects):
$range = $request->headers->get('Range');
preg_match_all ('/.*?(\d+).*?(\d+)/is', $range, $matches);
$limit = $matches[2][0];
$offset = $matches[1][0];
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM table LIMIT {$limit} OFFSET {$offset}";
$result = $db->execute($sql);
$sql2 = "SELECT FOUND_ROWS()";
$count = $db->execute($sql2);
$response->setContent($result);
$response->headers->set('Content-Range', "items $offset-$limit/{$count}");
In jsonRest documentation there is some information.

Dojo datagrid won't display inside another div

I'm trying to get a Dojo datagrid working - I have replicated the first example on the documentation page (http://docs.dojocampus.org/dojox/grid/DataGrid) & it works just fine.
However, when I try to display the grid inside another div (i.e. putting 'gridContainer4' from the example inside any other div) nothing displays...
Any help would be much appreciated - can't find anything about this anywhere online!
Finally figured it out:
The example text creates the new dojox.grid.DataGrid and applies it to "document.createElement('div')" - changing this to the ID of an existing div fixed the problem (rather than appendChild-ing it to another div)
Original code:
var grid4 = new dojox.grid.DataGrid({
query: {
Title: '*'
},
store: store4,
clientSort: true,
rowSelector: '20px',
structure: layout4
}, document.createElement('div'));
changes to:
var grid4 = new dojox.grid.DataGrid({
query: {
Title: '*'
},
store: store4,
clientSort: true,
rowSelector: '20px',
structure: layout4
}, "gridContainer4");