ExtJS: Adding spinner to combobox - extjs

I need/would like to add a spinner (up and down arrows) to an Ext JS (6.6.0) Ext.form.field.ComboBox. Something like this:
The requirement is to keep the combobox functionality but also add the possibility to step through the list step by step.
I have to admit that I am quite new to Ext JS. I did some research and went through the Ext JS documentation a bit but I still have no clear idea how to best implement this.
Can anybody suggest something?

The easiest solution to your problems would be to add triggers.
This is the same technique that the combobox is using to apply a "trigger" (button) to the field.
Triggers have a handler config in which you can access (on user click) the combobox. From there you can easily access the current value and the store to get all the information you need to set the "next" or "last" value in relation to the values store position.
Here is a working live example: sencha fiddle
Here is a code example:
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "AL",
"name": "Alabama"
}, {
"abbr": "AK",
"name": "Alaska"
}, {
"abbr": "AZ",
"name": "Arizona"
}]
});
// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
triggers: {
spinner: {
type: 'spinner',
upHandler: function () {
const me = this,
position = me.getValue() ? me.getStore().indexOf(me.findRecordByValue(me.getValue())) - 1 : -1;
if (position >= 0) {
let newValue = me.getStore().getAt(position).get(me.valueField);
if (newValue) {
me.setValue(newValue);
}
}
},
downHandler: function () {
const me = this,
position = me.getValue() ? me.getStore().indexOf(me.findRecordByValue(me.getValue())) + 1 : 0;
if (position < me.getStore().getRange().length) {
let newValue = me.getStore().getAt(position).get(me.valueField);
if (newValue) {
me.setValue(newValue);
}
}
}
}
}
});

Related

Kendo Grid pagination button shows in vertical format

I have a Kendo grid in my application and I am binding data to it through REST call. When the grid load first time, the buttons doesn't show up. Below is the example:
There are 400+ items in the grid, currently it is configured to show only 50 items per page. But the problem is I am not able to see options to visit second/next page.
Option of second page is visible when I change items per page. Like If I change option from 50 - 100. I am able to see other page number.
This is the second Problem. Page number appears in vertical way instead of horizontal.
I need help in solving below issues:
When Page Load pagination options should be displayed as they are suppose to be.
Pagination numbers should appear in horizontal way not in vertical way.
Below is my code snippet:
$scope.mainGridOptions = {
editable: true,
pageable: {
pageSizes: [15,25,50,100]
},
navigatable: true,
sortable: true,
filterable: true,
dataSource: {
type: "odata",
pageSize: 50,
batch: false,
requestEnd: function(e) {
if (e.type != 'read')
{
$('#grdItemizations').data('kendoGrid').dataSource.read();
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", editable: false },
Title: { type: "string",editable: false }
}
},
data: function (data) {
return data.d && data.d.results ? data.d.results : [];
}
},
transport: {
parameterMap: function (data, type) {
if (type != "read") {
var strIfy = kendo.stringify({
"__metadata": type != "create" ? { "type": },
"Title": data.Title,
"Id": type != "create" ? data.ID : undefined
});
return strIfy;
}
return kendo.data.transports["odata"].parameterMap.apply(this, arguments);
},
read: {
},
update: {
},
create: {
},
error: function (e) {
alert("Status: " + e.status + "; Error message: " + e.errorThrown);
}
},
},
columns: [
{ field: "Id", title: "ID" , width: "60px"},
{ field: "Title", title: "Analytic Inventory Description" , width: "220px"}
]
}
Any hint, help is really appreciated.
There can be other issues since you have not posted complete code.
First of all , I suspected there was was something off(missing css,incorrect version of kendo css referred, murtiple css conflicting) on css side since that deals with the presentation of grid .
Then i pulled up a demo and removed these css files
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.1.118/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.1.118/styles/kendo.bootstrap.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.1.118/styles/kendo.bootstrap.mobile.min.css" />
and see the image below surprisingly the result are kind of little similar i can see pagination button in a vertical format.
Please double check something is off on css side(check reference to kendo grid css by looking at viewsource page) if that does not solve problem make sure you post the complete code

Loading different view port based on input parameter

Currently, we use an embedded tomcat, to start up ext-js application locally.
The Ext.application contains below code that loads the view port:
var viewPort = Ext.create('Ext.container.Viewport', {
layout : 'fit',
items: [
Ext.create('Ext.tab.Panel', {
items: [
Ext.create('Tab 1', {title: ' Tab 1'}),
Ext.create('Tab 2', {title: ' Tab 2'}),
],
}),
]
});
Can I load the tab2, above in the panel on condition basis. How can I configure say an option, some where in the web-application that loads tab2 only if the option is set?
For better clarification, something like -
// load tab 1
if (optionSet) {
// then load tab 2
}
Is this even possible? Thanks!
See if this snippet helps you:
var items = [{
xtype:'tab1'
,title:'Tab 1'
}];
if(condition) {
items.push({
xtype:'tab2'
,title:'Tab 2'
});
}
var viewPort = Ext.create('Ext.container.Viewport',{
layout:'fit'
,items:[{
xtype:'tabpanel'
,items:items
}]
});

How to find grid array in the browser ExtJs

Suppose if i have created a grid store like this
var store = Ext.create('Ext.data.ArrayStore', {
fields:['id','title', 'director', 'released', 'genre','tagline', 'price', 'available'],
data: [
[
1,
"Office Space",
"Mike Judge",
"1999-02-19",
1,
"Work Sucks",
"19.95",
1
],
[
3,
"Super Troopers",
"Jay Chandrasekhar",
"2002-02-15",
1,
"Altered State Police",
"14.95",
1
]
]
});
when i run it on browser i could not see anything because it has already been saved in the browser's memory , we need to display it to the the grid to see those data.
if i am editing the grid in the browser using editors plugin, so how can i see the changes made to the grid store? how to see it ?
You can add storeId to the store and then you can use the following global function:
Ext.StoreManager.lookup('storeId');
with this function you can always get the store from anywhere.
the gridpanel has the edit( editor, e, eOpts ) event which can be used after editing is complete.
Example:
var store = Ext.create('Ext.data.ArrayStore', {
storeId: 'gridStore',
(...)
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
(...),
listeners: {
edit: function(editing, e, eOpts) {
var record = e.record;
console.log('Changes on this record: ', e.record.getChanges());
console.log('Original value: ', (editing.ptype == 'cellediting' ? e.originalValue : e.originalValues));
console.log('New value: ', (editing.ptype == 'cellediting' ? e.value : e.newValues));
}
}
});
//for save on a toolbar
var button = Ext.create('Ext.button.Button', {
text: 'Save',
(...),
handler: function() {
var gridStore = Ext.StoreManager.lookup('gridStore');
console.log('all added, but not synchronized records: ', gridStore.getNewRecords());
console.log('all edited, but not synchronized records: ', gridStore.getUpdatedRecords());
console.log('all modified(added and edited), but not synchronized records:', gridStore.getModifiedRecords());
console.log('all removed, but not synchronized records:', gridStore.getRemovedRecords());
}
});
I'd say it depend.
First, to display you store in a grid, it should be something like this (simplified), following your code:
var grid = Ext.create('Ext.grid.Panel', {
title: 'Test',
store: store,
columns: [
{ text: 'title', dataIndex: 'title' },
{ text: 'director', dataIndex: 'director', flex: 1 }
],
height: 200,
width: 400
});
var MyWindow = Ext.create('widget.window',{width:400,height:200,items:[grid]});
MyWindow.show();
You assigned your store to a local variable "store". Normaly, if you use that store in a grid, and you make changes in that grid, it should reflect in the store.
When you make it editable with the editable grid plugin, changes are directly writen in the store, so this should work:
var currentStoreContent = store.data.items;
or, from the grid:
var currentStoreContent = grid.getStore().data.items

Backbone-UI, TableView, rendering columns

I'm trying to render a table view with four columns, 'name', 'birthday', 'gender', 'married', but
a) they columns aren't showing up at all
b) I'm not even sure if I am passing them correctly, because when I console.log table.options the columns property is rendered as "empty":
Object {columns: Array[0], emptyContent: "no entries", onItemClick: function, sortable: false, onSort: null}
I've tried this:
var table = new Backbone.UI.TableView({
model: people,
columns: [
{ title: "Name", content: 'name' },
{ title: "Gender", content: "gender" } },
{ title: "Birthday", content: "birthday" } },
{ title: "Married", content: "married" } }
]
});
And this:
var table = new Backbone.UI.TableView({
model: people,
options: {
columns: [
{ title: "Name", content: 'name' },
{ title: "Gender", content: "gender" },
{ title: "Birthday", content: "birthday" },
{ title: "Married", content: "married" }
]
}
});
The source code change is adding the options as mu is too short said. Change the initialize method of the Backbone.UI.TableView object to be the following within the source code:
initialize : function(options) { //add parameter
Backbone.UI.CollectionView.prototype.initialize.call(this, arguments);
$(this.el).addClass('table_view');
this._sortState = {reverse : true};
this.options = _.extend({}, this.options, options); //Add this line
}
I'm sure there might be a better place to put this but I'm just going through tutorials to learn some advanced backbone stuff considering the documentation does not match the current version I would shy away from using the library in production as of right now. Hopefully it is fixed in the future.

Can't change selectfield options - InCode

Here is my select field. We can see that the options are SI,American and Imperial
{
xtype: 'selectfield',
flex: 1,
itemId: 'units_Selector',
maxHeight: 50,
label: 'Units',
options: [
{
text: 'SI',
value: 'SI'
},
{
text: 'American',
value: 'American'
},
{
text: 'Imperial',
value: 'Imperial'
}
],
usePicker: false,
listeners: [
{
fn: function(element, eOpts) {
var unit = Ext.getStore('configstore').last().get('Units');
this.suspendEvents();
this.setValue(unit);
this.resumeEvents();
},
event: 'painted'
}
]
},
Here what I see when using my app...
OUPS seems like SI is displayed has International?
FYI - International was the option's name I gave this option at first. I decide to change it but my app seems to disagree with me on this one ....
Here is a console.log() of my selectfield's options
And here is the funniest part, my code.js file to see that it does save to it correctly from sencha architect
Would anyone know how to repair that problem...?
Answer is dumb...
Seriously, if you have multilanguage app... double check you aint modifing the value field -_-< when updating the language (text field).
found the problem by changing the itemId to something else to see who what changing the value of this select field. (Automaticly created an error and gave me a code line to find it)

Resources