EXTJS 4 Grid selection model row - extjs

I have a grid and when I click on a button in the toolbar of the panel I want to check if a row in the grid is selected.
If true I need de value of one cell of that row, so I can put it behind a url.
But I have no idea how I can use the selection model to get the cell value of a selected row in EXT JS 4.

Perhaps try something like:
grid.getSelectionModel().getSelection()
This will return an array of all selected records withing the grid.
Then, you can iterate over the selection, find your row and call row.get('PropName') to get the value.
Hope this helps.

You're approaching the issue backwards though. You want to register for the 'selectionchange' event from the grid.
thisController.control ({'#mygrid':
{
selectionchange:onSelectionChange}
});
function:onSelectionChange(model, selected, eOpts )
{
//do work here
}
So basically you want to create an event driven model.

Related

AgGrid loose edit mode when data is updated

I use AgGrid Enterprise, and allow users to edit an entire row so all cells switch to edit mode.
I also have an event listener to save the row in database when the user put the focus on a new line or outside the grid.
In the first column of my grid, i have a custom cell displaying a combo.
When the user select a value, it should update the cell AND 3 other cells in the row.
So i use the API to refresh the 3 cells.
Doing so put the cell in view mode, i loose the edit mode and the save event is triggered.
Is there a way in edit mode, to update cell content without loosing the edit mode ??
Thanks a lot.
You said your are try to entire row and and also have custom cell with combo
but ag-grid does not work any popup editor with full row edit.
You have to remove ag-grid property editType: 'fullRow' and it will work.
https://www.ag-grid.com/javascript-grid-cell-editing/#gsc.tab=0

Reload grid selection after deletion of row in extjs

I have a grid with one column, which when the user selects, is used to display information in various textfields, checkboxes which are embedded in a panel on the right. I have implemented a delete feature at the row level in the grid. Now I wish either of these two things to happen.
1) Either the default selection is such that the first row is by default selected after deletion of any row.
OR
2)The information in the various components in the panel on the right is cleared.
Currently what happens is that the information which corresponds to the deleted row stays after deletion since nothing is selected in the grid so the previous selected option is used to display information on the right.
As removing the record from the grid implies deselecting it, you really just need to listen for changes to the selection in your grid and implement the desired behaviour when no selection exists.
I'd recommend the selectionchange event, as you can cover both selection and deselection by inspecting the new selection state:
grid.on({
'selectionchange': function(sm, selectedRecords) {
if (selectedRecords.length === 0) {
// no selection -> clear fields or select the first row
} else {
// selection exists -> load data into fields
}
}
});
(assuming you're using single selection, i.e. either one or no row can be selected)

Simulate a click event on a grid row

How can I dynamically click rows in my grid?
E.g.: I am using border layout.
I have a grid in the west with a list of Companies.
When I click on a Company, the information of the company which has an Id, is displayed in a form in my center area.
Now, when I want to add a company ( I am doing this with a button which opens a "Add window"), and type all information in the form and then press "save", I reload the grid.
How could I make it, that the company which is newly added, is clicked on and its information is displayed in the center area.
NOTE: The companies are listed with an ajax request, and the information is called with a "onCompanyGridHandler".
You can make the new campany created added in the top of the grid by sorting the grid's store with, for example, the date of campany creation. You can so add this line in the grid's store:
sorters: { property: 'datecreate', direction : 'DESC' },
Then, after the campany creation, you select the first row of the grid, using this code:
Ext.getCmp('your_grid_id').getView().select(0);
There are a couple of approaches you can take here:
In the function where you add the data from the Add Window to the grid panel's store, you can also get the form and use the form's loadData() method to load the data into the form, populating both the Grid and Form at the same time.
As is mentioned in a comment, after adding the data to the grid's
store, make fire the click event on the row in the grid that is
displaying the new data. I prefer the first approach because you do
not have to find the correct row in the grid and fire its click
event. In the first approach both the grid and form are loaded
with the data directly.
David

updating an ng-grid cell

I'm displaying an ng-grid and I would like to change a particular cell's content based on an update. I don't want to make the cell editable. I'm instead popping up a dialog when they click on a Row. When they submit the data, I update the db using ajax, but I don't want to refresh the page. I'd like to update the cell to say something like "Updated". I haven't found anything in documentation or examples that would allow me to modify a particular cell on the fly. Anybody wanna point me in a right direction?
I do something similar with my data. Use a row or cell template to show your dialog using ng-click and pass a reference to the row.entity to your dialog. Then you can just update the data on the row.
I created an example below where I have a cell template that has an event to capture the row, column, and cell data. Then I allow for the user to update the value, and on the button click I update the row with the new value.
Plunkr here:
http://plnkr.co/edit/JQ7mtD?p=preview

On Click on the RowHeader the current row should be editable and On click of the columnHearder current column of all row should be editable

I have a silverlight DataGrid, by default on page load the all the cells of the datagrid should be Readonly. I have 2 problem , can any one help me?
1.On Click on the RowHeader the current row should be editable
2. On click of the columnHearder current column of all row should be editable
This might not solve your entire problem but it should partially address it.
This is to make a column read-only in a datagrid
DataGrid.Columns[7].IsReadOnly = true;
Obviously the property can be changed from events but the data grid does not have row/column headers event handlers. Custom controls seem the way to go without introducing any new gui elements like buttons and changing the feel of the application.

Resources