ExtJs Calendar EventStore help? - extjs

I have been trying to set up a baisc calendar example to play around with using ExtJs Calendar.
I have looked at examples and documentation on
Ext Calendar Pro.
I am having difficulty just getting the basic calendar example to work.
I think my problem is that I am not defining the store correctly, I know that the store should contain records of type 'Ext.calendar.EventRecord'.
What type of store/reader should i use to read records?
Here is my code:
var recs = [];
rec = new Ext.calendar.EventRecord({
StartDate: '2101-01-12 12:00:00',
EndDate: '2101-01-12 13:30:00',
Title: 'My cool event',
Notes: 'Some notes'
});
recs[0] = rec;
store = new Ext.data.Store({
data: recs,
reader: new Ext.data.ArrayReader({
fields: ['StartDate', 'EndDate', 'Title', 'Notes']
})
});
Ext.apply(this, config, {
title: 'calendar',
layout: 'fit',
activeItem: 1,
eventStore: store
});//Ext.apply

Looking at this example, it looks like you need to be using a JsonStore (which has a JsonReader):
new Ext.data.JsonStore({
id: 'eventStore',
root: 'evts',
data: eventList, // defined in event-list.js
proxy: new Ext.data.MemoryProxy(),
fields: Ext.calendar.EventRecord.prototype.fields.getRange(),
sortInfo: {
field: 'StartDate',
direction: 'ASC'
}
});
With eventList defined as follows:
var eventList = {
"evts": [{
"id": 1001,
"cid": 1,
"title": "Vacation",
"start": today.add(Date.DAY, -20).add(Date.HOUR, 10),
"end": today.add(Date.DAY, -10).add(Date.HOUR, 15),
"ad": false,
"notes": "Have fun"
}]
}
If you're using a remote provider, simply change your data property in the EventStore to load from a url instead. Your JSON response should be in a structure as defined by eventList.
Hope that helps.

Related

How to implement Ext js Calender in version 4.2

I am getting error when trying to implement Ext js Pro calendar in ext js 4.2
error is Cannot read property 'add' of undefined in line var startDate = Extensible.Date.add(Ext.Date.clearTime(start || new Date(), true)) in AbstarctCalndar.js;
My intail Code is
Ext.Loader.setConfig({
enabled: true,
disableCaching: false,
paths: {
"Extensible": "extjs/src/extensible/src",
"Extensible.example": "extjs/src/extensible/examples"
}
});
Ext.require([
'Extensible.calendar.data.MemoryEventStore',
'Extensible.calendar.CalendarPanel',
'Extensible.example.calendar.data.Events'
]);
Here is simple code in app.js
Ext.onReady(function () {
var eventStore = Ext.create('Extensible.calendar.data.MemoryEventStore', {
// defined in ../data/Events.js
data: [{
"id": 1001,
"CalendarId": 1,
"StartDate": "2015-03-18",
"EndDate": "2015-03-28",
"Title": "Vacation",
"Notes": "Have fun"
}]
});
//
// example 1: simplest possible stand-alone configuration
//
var cal = new Ext.create('Extensible.calendar.CalendarPanel', {
eventStore: eventStore,
title: 'Basic Calendar',
width: 700,
height: 500
});
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
width: 100,
height : 100,
border : true,
frame : true,
layout: 'auto',// auto is one of the layout type.
items: [cal]
});
});
Please give sample data of Event store data and Calendar Store Data.
Please suggest working code both in MVC and onReady

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.

Dyanmic forms from json file in sencha touch

How can I create dynamic form where all the fields are coming from a json file in sencha touch?
(Additional details transferred from "answer")
My json looks like it
{
success: true,
data: [
{xtype: "textfield", title: "label1", name: "textfield1"},
{xtype: "emailfield", title: "label2", name: "textfield2"},
{xtype: "passwordfield", title: "label3", name: "textfield3"},
{xtype: "button", title: "button", name: "button"}
]
}
I want a sepearte controller and a view.
i did it in a single controller file like this
form = Ext.create('MyApp.view.MyDataView');
var test=this;
var ajax = Ext.Ajax.request({
url: 'contacts.json',
method: 'get',
success: function(response)
{
console.log(response);
response = Ext.JSON.decode(response.responseText);
this.hello=response;
console.log(response.data.length);
for (var i = 0; i < response.data.length; i++)
{
form.add({
xtype: response.data[i].xtype,
id:response.data[i].title,
action:response.data[i].title,
label: response.data[i].title,
name: response.data[i].name
});
}
console.log(form.getValues());
form.setLayout();
form.show(document.body);
Ext.Viewport.animateActiveItem(form,{type: 'flip', direction: 'right'});
}
there is some problem i m facing regarding the utton tap event and if multiple buttons are there giving event to them is not yet possible for me ....can anybody help me regarding this ..
Have you tried something yet?
You can just create the form in the file like something like this:
{
xtype: 'form',
items: [ //...
]
}
Then you can load your file in, and decode it into a variable.
Ext.Ajax.request({
url: 'yourform.json',
success: function(response){
var formInJson = response.responseText;
var form = Ext.JSON.decode(formInJson);
//... do something with your form
}
});

ExtJs Calendar store load help?

I have set up an ExtJs calendar. However the store gets loaded 4 times initially even though I have not called the store.load method. I'm just wondering where this is getting called from? As it is also sending start and end dates in the wrong format to the server. i.e. it sends dates in the format m/d/y whilst the server expects d/m/y?
this.eventStore = new Ext.data.JsonStore({
id: 'eventStore',
root: 'Data.items',
proxy: new Ext.data.HttpProxy({
url: AppRootPath + 'Calendar/GetCalendarData',
method: 'POST'
}),//proxy
fields: [
{name:'StartDate', mapping: 'start', type: 'date', dateFormat: 'd F Y'},
{name:'EndDate', mapping: 'end', type: 'date', dateFormat: 'd F Y'},//H:i:s
{name:'Title', mapping: 'title', type: 'string'},
{name:'Notes', mapping: 'notes', type: 'string'},
{name:'CalendarId', mapping: 'cid', type: 'string'}]
});
The Calendar:
this.calendar = new Ext.calendar.CalendarPanel({
activeItem: 2,
id: 'calendar',
eventStore: this.eventStore,
calendarStore: this.calendarStore,
headerCfg: {
tag: 'center',
cls: 'x-panel-header x-unselectable'
},
monthViewCfg: {
showHeader: true,
showWeekLinks: true,
showWeekNumbers: true
},
title: 'My Calendar', // the header of the calendar, could be a subtitle for the app
listeners: {
'eventclick': {
fn: function(vw, rec, el){
alert('#EventClicked');
debugger
},
scope: this
},
'dayclick': {
fn: function(vw, dt, ad, el){
alert('#DayClicked');
},
scope: this
},
'viewchange': {
fn: function(p, vw, dateInfo){
updateTitle.apply(this, [dateInfo.viewStart, dateInfo.viewEnd]);
Ext.getCmp('app-nav-picker' + config.id).setValue(dateInfo.activeDate);
},
scope: this
},
'eventmove': {
fn: function(vw, rec){
rec.commit();
//var time = rec.data.IsAllDay ? '' : ' \\a\\t g:i a';
//this.showMsg('Event '+ rec.data.Title +' was moved to '+rec.data.StartDate.format('F jS'+time));
},
scope: this
}
}
});
I presume the load method is being called from the Calendar-all.js file. However I cant find exactly where?
Can I intercept these load calls to ensure the dates is in the correct format?
This is a bug in the Ext 3.3 example version. Each view load (month / week / day) causes a separate store load call. This (along with lots of other stuff) has been fixed in the Ext Calendar Pro version of the components (examples here). The date format is also configurable in the Pro version via the CalendarView.dateParamFormat config. You can certainly fix those things yourself, but I'd recommend that you try out the Pro version and see if it suits your needs better out of the box.
Yes you can stop that initially loading store at calender.. Its loading even thought we have made it autoload: false.
examples/calendar/src/view/AbstractCalendar.js
Line#717
comment the code
/*this.store.load({
params: {
start: Ext.Date.format(this.viewStart, 'm-d-Y'),
end: Ext.Date.format(this.viewEnd, 'm-d-Y')
}
});*/
now extra loading stop and u can execute store whenever u want. :)

Resources