Automatically trigger change event in kendo detail grid - angularjs

I have a angular kendo grid similar to the telerik demo.
Main Grid:
$scope.mainGridOptions = {
dataSource: {
transport: {
read: queryurl
},
pageSize: 5,
},
sortable: true,
pageable: true,
detailTemplate: kendo.template($("#template").html()),
dataBound: function () {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
}
Detail Grid:
$scope.detailGridOptions = function (item) {
return {
dataSource: {
transport: {
read: detailsUrl
},
},
change: $scope.showDocument,
selectable: "row",
dataBound: function (e) {
var row = e.sender.tbody.find("tr:first");
row.addClass("k-state-selected");
row.trigger("change") //doesnt work!
}
}
}
When the user clicks a row in the detail grid a document is rendered in a jquery dialog. This all works as expected.
When the grid loads, the first master-row is expanded. Now I need the change event of the first row in the detailsgrid to fire automatically, so that the first document of the first entry gets displayed automatically, when the app loads.
As I was able to highlight the first detailrow I thought that i could trigger the change event like this: row.trigger("change") but this doesn't seem to work.
Any ideas are much appreciated!

Try using the select method of the grid to select the row instead of manually adding the "k-state-selected" class. It will automatically trigger the change event for you. JsBin example.
(function() {
'use strict';
var grid = $('#grid').kendoGrid({
dataSource: [
{ name: 'Brett', age: 37 },
{ name: 'Susan', age: 38 }
],
selectable: 'row',
change: function (e) {
console.log('change triggered');
},
dataBound: function (e) {
var row = this.tbody.find('tr:first');
this.select(row);
}
}).data('kendoGrid');
})();

Related

ExtJS 6.2 - controller keeps looking stores in my cotroller path

I'm new in extJS and i've been working in an app for some time.
My problem is that I have an app with an MVC architecture and as I instatiate the controller I declare de stores. But when I run this app in the browser, for some reason the controller is trying to get the store from my controller folder.
I have other controllers runing in my app and all of them looks for the store in the stores folder.
Does anyone have a clue about this issue?
Thanks
Ext.define('SGE.controller.staticData.AbstractController', {
extend: 'Ext.app.Controller',
requires: [
'SGE.util.Util'
],
stores: [
'Actors',
'staticData.Categories',
'staticData.Cities',
'staticData.Countries',
'staticData.Languages'
],
views: [
'staticData.AbstractGrid',
'staticData.Actors',
'staticData.Categories',
'staticData.Cities',
'staticData.Countries',
'staticData.Languages'
],
init: function(application) {
this.control({
"staticdatagrid": {
render: this.render,
edit: this.onEdit
},
"staticdatagrid button[itemId=add]": {
click: this.onButtonClickAdd
},
"staticdatagrid button[itemId=save]": {
click: this.onButtonClickSave
},
"staticdatagrid button[itemId=cancel]": {
click: this.onButtonClickCancel
},
"staticdatagrid button[itemId=clearFilter]": {
click: this.onButtonClickClearFilter
},
"staticdatagrid actioncolumn": {
itemclick: this.handleActionColumn
},
"citiesgrid button[itemId=clearGrouping]": {
toggle: this.onButtonToggleClearGrouping
}
});
this.listen({
store: {
'#staticDataAbstract': {
write: this.onStoreSync
}
}
});
if (!Ext.getStore('countries')) {
Ext.create('SGE.store.staticData.Countries');
}
if (!Ext.getStore('languages')) {
Ext.create('SGE.store.staticData.Languages').load();
}
if (!Ext.getStore('actors')) {
Ext.create('SGE.store.staticData.Actors');
}
if (!Ext.getStore('categories')) {
Ext.create('SGE.store.staticData.Categories');
}
},
onStoreSync: function(store, operation, options){
Packt.util.Alert.msg('Success!', 'Your changes have been saved.');
console.log(store);
console.log(operation);
console.log(options);
},
render: function(component, options) {
component.getStore().load();
if (component.xtype === 'citiesgrid' && component.features.length > 0){
if (component.features[0].ftype === 'grouping'){
component.down('toolbar#topToolbar').add([
{
xtype: 'tbseparator'
},
{
xtype: 'button',
itemId: 'clearGrouping',
text: 'Group by Country: ON',
iconCls: 'grouping',
enableToggle: true,
pressed: true
}
]);
}
}
},
onEdit: function(editor, context, options) {
context.record.set('last_update', new Date());
},
onButtonClickAdd: function (button, e, options) {
var grid = button.up('staticdatagrid'),
store = grid.getStore(),
modelName = store.getProxy().getModel().modelName,
cellEditing = grid.getPlugin('cellplugin');
store.insert(0, Ext.create(modelName, {
last_update: new Date()
}));
cellEditing.startEditByPosition({row: 0, column: 1});
},
onButtonClickSave: function (button, e, options) {
button.up('staticdatagrid').getStore().sync();
},
onButtonClickCancel: function (button, e, options) {
button.up('staticdatagrid').getStore().reload();
},
onButtonClickClearFilter: function (button, e, options) {
button.up('staticdatagrid').filters.clearFilters();
},
handleActionColumn: function(column, action, view, rowIndex, colIndex, item, e) {
var store = view.up('staticdatagrid').getStore(),
rec = store.getAt(rowIndex);
if (action == 'delete'){
store.remove(rec);
Ext.Msg.alert('Delete', 'Save the changes to persist the removed record.');
}
},
onButtonToggleClearGrouping: function (button, pressed, options) {
var store = button.up('citiesgrid').getStore();
if (pressed){
button.setText('Group by Country: ON');
store.group('country_id');
} else {
button.setText('Group by Country: OFF');
store.clearGrouping();
}
}
});
Browser response
enter image description here
An ExtJs Controller pulls in the specified store files before rendering its UI. Assuming that you have not created any store files (assumption form your init function where you created the store if they do not exist), it first searches the store files to load them into the memory.
Another possible problem may be the store has a different namespace than that of the application, you will need to specify the full class name as well as define a path in the Loader's paths config or setPath method.
Refer doc ExtJs Controller's Stores.

extjs contextmenu click, pass parent grid as parameter to controller method

Inside my extjs grid, when I right click I call a context menu. When I click on one of the items I want to launch a method in the controller. This all works successfully, problem is I want to pass the parent grid that this is being called from into the controller method. Can someone please show me how to do this?
This is my context menu
Ext.define('Example.ContextMenuTradematch', {
xtype: 'contextMenuTradematch',
extend: 'Ext.menu.Menu',
items: [
{
text: 'Match Trade',
iconCls: 'greenIcon',
listeners: {
click: {
fn: 'onMatchTrade',
params: {
param1: this
}
}
}
},
{
text: 'Delete Trade',
iconCls: 'deleteIcon',
listeners: {
click: 'onDeleteTrade'
}
}
]
});
then this is my controller method
onMatchTrade: function (event, target, options) {
debugger;
var me = this;
How can I access the grid that the event originated from?
--and this is how I add the context menu to the grid
title: 'Tradematch Results: UNMATCHED',
xtype: 'grid',
itemId: 'gridUnmatchedId',
ui: 'featuredpanel-framed',
cls: 'custom-grid',
margin: '0px 10px 0px 10px',
flex: 2,
width: '100%',
bind: {
store: '{myTM_ResultsStore}'
},
listeners: {
itemcontextmenu: 'showContextMenuTradematch'
},
and this is how the controller adds it...
getContextMenu: function (cMenu) {
if (!this.contextMenu) {
debugger;
this.contextMenu = this.getView().add({ xtype: cMenu });
}
return this.contextMenu;
},
showContextMenuTradematch: function (view, rec, node, index, e) {
e.stopEvent();
e.stopEvent();
debugger;
this.getContextMenu('contextMenuTradematch1').show().setPagePosition(e.getXY());
return false;
},
The easiest way to do this is when you create your Example.ContextMenuTradematch instance - that I'm assuming you do from a itemcontextmenu listener - then you could pass a reference to the grid.
itemcontextmenu: function (grid, record, item) {
// code to create your menu
// probably something like:
if (!grid.contextMenu) {
grid.contextMenu = Ext.create('Example.ContextMenuTradematch', {
ownerGrid: grid
});
}
grid.contextMenu.showBy(item);
}
If onMatchTrade was fired by clicking on an Ext.menu.Item instance then it's signature will be:
onMatchTrade: function (item, e) {
var menu = item.up('menu'),
grid = menu.ownerGrid;
console.log(grid);
}
There was a lot of guessing here. If this is not how you are creating your menu or calling the methods, adding a fiddle with the issue would help.
Here is a fiddle to use as template: https://fiddle.sencha.com/#view/editor&fiddle/24fc

Difficulting initializing a Kendo grid in an AngularJS controller

I'm trying to bind some data to a Angular-Kendo UI grid, but as soon as I click on the tab which contains my grid widget I get this error below :
Error: error:unpr
Unknown Provider
Unknown provider: $modalInstanceProvider <- $modalInstance
Description
This error results from the $injector being unable to resolve a required dependency.
I'm not really sure why it's crashing on $modalInstance since I'm trying to wire up my Kendo grid with some data. This is strange.
Here's my HTML :
<div data-ng-controller="GridSettingsCtrl" class="col-md-4">
<div class="col-lg-12">
<h3>Choose a Dimension grouping</h3>
<span id="userDimenGrid" kendo-grid="userDimenGrid"
k-data-source="userDimenGridDS"
k-options="userDimenGridOptions"
k-rebind="userDimenGridOptions" />
</div>
</div>
and here's my Angular controller code :
FYI: the HTML attrib k-data-source="userDimenGridDS" is wired to Kendo DataSource $scope.userDimenGridDS in my js code - which in turn calls read: getUserDimensionsList for the data.
(function () {
'use strict';
angular.module('rage')
.controller('GridSettingsCtrl', ['$scope', '$modalInstance', 'datacontext', 'widget', gridSettings]);
function gridSettings($scope, $modalInstance, datacontext, widget) {
var settings = this;
// add widget to scope
$scope.widget = widget;
// set up result object
$scope.result = jQuery.extend(true, {}, widget);
$scope.ok = function () {
$modalInstance.close($scope.result);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
$scope.userDimenGridOptions = {
selectable: true,
sortable: true,
pageable: true,
columns: [
{ field: "id", width: "10px", hidden: true },
{ field: "dimension", width: "80px", editor: dimenDropDown, template: "#=dimension#" }, // DropDown editor defined !!
{ field: "hierarchy", width: "60px" },
{ command: [{ name: "edit", text: '' }, { name: "destroy", text: '' }], width: 120 }
],
editable: "inline",
toolbar: ["create"],
};
// SERVER-SIDE DIMENSIONS DATA SOURCE - see dimenDropDown()
$scope.dimensionsDataSource = new kendo.data.DataSource({
transport: {
read: getDimensionsFromServer
}
});
// USER DIMENSIONS DATA SOURCE !!
$scope.userDimenData = [];
$scope.userDimenGridDS = new kendo.data.DataSource({
transport: {
read: getUserDimensionsList,
create: function (options) {
options.success(options.data);
}
},
schema: {
model: {
id: "id",
fields: {
dimension: { type: "string" },
hierarchy: { type: "boolean" }
}
}
},
pageSize: 5
});
// SERVER-SIDE DIMENSIONS DATA SOURCE - see dimenDropDown()
$scope.dimensionsDataSource = new kendo.data.DataSource({
transport: {
read: getDimensionsFromServer
}
});
}; // end of gridSettings()
function getUserDimensionsList(options) {
// Retrieve user dimensions list from server or local cache, and return to Kendo Grid DataSource.
// Called by: read option of $scope.dimenUserGridDS
var userDimenFromStorage;
if ($scope.readUserDimensionsFromCache) { // pull from cache
userDimenFromStorage = reportsContext.getUserDimenFromLocalStorage();
}
if ($scope.readUserDimensionsFromCache && userDimenFromStorage != null && userDimenFromStorage.length != 0) {
options.success(userDimenFromStorage);
}
else { // pull from server
datacontext.getDimenUserList().then(function (data) {
if (data.status == 'FAIL') {
if (data.messages.length > 0) {
logErr("Error retrieving user Dimensions list: " + data.messages[0]);
return;
}
}
else {
// RETURN DUMMY REC FOR TESTING...
$scope.userDimenData = data;
options.success($scope.userDimenData);
}
});
}
}
function getDimensionsFromServer(options) {
datacontext.getDimensionsFromServer().then(function (data) {
if (data.status == 'FAIL') {
if (data.messages.length > 0) {
logErr("Error retrieving KRI list: " + data.messages[0]);
return;
}
}
else {
options.success(data.data);
}
});
}
// USER DIMENSION DROPDOWN FOR GRID
function dimenDropDown(container, options) {
$('<input id="dimenDropDown" data-text-field="name" data-value-field="name" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoComboBox({
dataTextField: "name",
dataValueField: "name",
dataSource: $scope.dimensionsDataSource
});
}
})();
and here's a screen shot to show the tab I click on to get my "Dimension Grouping" grid, which of course does not render yet due to the error:
As I mentioned, the error occurs as soon as I click on that "Dimensions" tab - which is when it should try and bind the data to the Kendo grid.
Here's a screen shot of that :
If anyone can see a problem with my code, your advice would be appreciated...
regards,
Bob
I found my problem. I'm using Malhar dashboard widget framework, which specifies the controller in it's settings.
Reference to Malhar dashboard on github: https://github.com/DataTorrent/malhar-angular-dashboard
So my HTML ended up looking like this, without the data-controller attrib:
<div class="col-md-4">
<div class="col-lg-12">
<h3>Choose a Dimension grouping</h3>
<span id="userDimenGrid" kendo-grid="userDimenGrid"
k-data-source="userDimenGridDS"
k-options="userDimenGridOptions"
k-rebind="userDimenGridOptions" />
</div>
</div>

ExtJS 4.2 resizable, draggable component

In my code I use MVC architecture. My view Component looks like this:
Ext.define('calendar.view.event', {
extend: 'Ext.Component',
alias: 'widget.event',
renderTo: Ext.getBody(),
initComponent:function(){
this.addEvents('eventClick');
this.callParent(arguments);
},
afterRender: function() {
this.mon(this.el, 'click', this.eventClick, this); //mon( item, ename, [fn], [scope], [options] ) - zkratka pro addManagedListener.
this.callParent(arguments);
},
eventClick: function (ev, t) {
var height = this.getHeight();
this.fireEvent('eventClick', this, height, ev);
}
});
Im firing Event on click for controller which is like this:
Ext.define('calendar.controller.eventsChange', {
extend: 'Ext.app.Controller',
views: ['event'],
init: function () {
this.control({
'event': {
eventClick: function (callerObject) {
this.editEvent(callerObject)
}
}
});
},
editEvent: function (callerObject) { //oznaci jako editovatelny
callerObject.get
if(callerObject.hasCls('SpecEv') || callerObject.hasCls('activeEvent'))
{
if (callerObject.hasCls('activeEvent'))
{
callerObject.removeCls('activeEvent');
callerObject.addCls('SpecEv');
this.application.fireEvent('reRender');
}
else
{
console.log(callerObject);
callerObject.addCls('activeEvent');
callerObject.removeCls('SpecEv');
Ext.apply(callerObject, {
resizable: {
pinned:true,
dynamic:true
},
draggable: true,
});
callerObject.setLocalX(0);
var parentWidth = Ext.getCmp('SpecEv').getWidth();
callerObject.setWidth(parentWidth);
}
}
}
});
The problem comes when with
Ext.apply(callerObject, {resizable: {
pinned:true,
dynamic:true
},
draggable: true,
});
When console.log shows me the object after my apply, it says draggable:true and resizable:true. Does anyone know where the problem is?
Thanks for reponses.
It can't works, because your code only set configuration properties, which are handled only when component is initializing. So when you set these properties on already constructed object nothing happen. Component resizability and draggability will not be initialized automatically after setting these properties.
You can try use Ext.Component initResizable and initDraggable methods. But these methods are internal and undocumented.
callerObject.initResizable({
pinned:true,
dynamic:true
});
callerObject.initDraggable();
Also you can try setup Ext.util.ComponentDragger and Ext.resizer.Resizer for your existing component manually.

Asscociating a store with Ext.menu.Menu

I am new to extjs.I want to associate a store on selecting a menu item from Ext.menu.Menu. I am using extjs 4.1.0. I searched on the net even went through sencha doc but I couldn't find any way to achieve this.
Is there some way to achieve it?
Thanks in advance.
I'm using a menu with a store in a project. Here's an example:
Ext.define("Ext.ux.menu.DynamicMenu", {
extend: "Ext.menu.Menu",
alias: 'widget.dynamicmenu',
loaded: false,
loadMsg: 'Loading...',
store: undefined,
icon: '',
constructor: function (config) {
var me = this;
Ext.apply(me, config);
me.callParent();
},
initComponent: function () {
var me = this;
me.callParent(arguments);
me.on('show', me.onMenuLoad, me);
listeners = {
scope: me,
load: me.onLoad,
beforeload: me.onBeforeLoad
};
me.mon(me.store, listeners);
},
onMenuLoad: function () { var me = this; if (!me.store.loaded) me.store.load(); },
onBeforeLoad: function (store) { this.updateMenuItems(false); },
onLoad: function (store, records) { this.updateMenuItems(true, records); },
updateMenuItems: function (loadedState, records) {
var me = this;
me.removeAll();
if (loadedState) {
me.setLoading(false, false);
Ext.Array.each(records, function (record, index, array) {
me.add({
text: record.get('DisplayName'),
data: record,
icon: me.icon
});
});
me.store.loaded = true;
}
else {
me.add({ width: 75, height: 40 });
me.setLoading(me.loadMsg, false);
}
me.loaded = loadedState;
}
});
I found this one on the sencha forums if IIRC, but can't find the link anymore. I made some tweaks for icons etc, ...
On the Ext.Array.each(records, ....
You'll need to define your own logic, It's depending on your model. My model has a DisplayName which I use to show as text. I also stock my record in a data property I made in the menu item. You're completely free there.
Good luck!

Resources