Hide table rows until search is performed - titanium

I have a basic SearchBar attached to a basic TableView. It works fine, but I don't want any table rows to display until the user starts typing in the search bar, so it is always filtered, and never will ALL matching rows display in the table.
var searchbar = Ti.UI.createSearchBar();
var tv = Ti.UI.createTableView({
data: myData,
search: searchbar,
hideSearchOnSelection: false,
filterAttribute: 'title',
});
How is it done?

You can try setting the tableView data to be empty when the page loads then set the data when the user starts typing in the searchbar, e.g.:
var searchbar = Ti.UI.createSearchBar();
searchbar.addEventListener('change', function(e){
Ti.API.info("calling change event");
var tableData = [ {title: 'Apples'}, {title: 'Bananas'}, {title: 'Carrots'}, {title: 'Potatoes'} ];
tv.data = tableData;
//Remove this event listener so the data is only set once
e.source.removeEventListener(e.type, arguments.callee);
});
var tv = Ti.UI.createTableView({
data: [{}],
search: searchbar,
hideSearchOnSelection: false,
filterAttribute: 'title',
height:Ti.UI.SIZE
});
var win = Ti.UI.createWindow()
win.add(tv);
win.open();

Related

How to put edited record on first position in grid after saveing chnages?

I am using Extjs 4.2.1 and I ask myself a while how to put an edited and saved record on top of the grid after the save process has taken place. So the user can see the effect of the saved change.
I tried to put some code between the success callback method of the save method of the store. It looks like this:
store.save({
success : function(rec, op, success) {
var selectionModel = Ext.getCmp('grid').getSelectionModel();
var selection = selectionModel.getSelection();
selectionModel.select(selection);
billRecordStore.insert(0, selection);
billRecordStore.reload();
Ext.getCmp('grid').getView().refresh();
}
But i have no idea how to get the changed record on top of the table....
Any ideas and helpful posts are very welcome!
Thanks for your help in advance!
when I edit a record, I do not use the load() or reload() method.
I use only the sync () method.
This way the edited register remain highlighted in the grid.
Something like this:
var values = form.getValues();
var record = form.getRecord();
record.set(values);
var store = grid.getStore();
store.sync({
success: function(){...},
failure: function(){...}
});
When I create a new record, I have the grid records sorted so that the last inserted record is displayed on the first line.
So when it does the load (), or loadPage(1), is always selected the first row of the grid that corresponds to the last inserted record.
Edited 26/06/2015
var form = Ext.ComponentQuery.query('#formitemId')[0];
var grid = Ext.ComponentQuery.query('#griditemId')[0];
var values = form.getValues();
var record = form.getRecord();
record.set(values);
var store = grid.getStore();
store.sync({
callback: function(){
var record1 = grid.getSelectionModel().getLastSelected(record);
form.loadRecord(record1);
},
scope: this,
success: function(){
var windowInfoCNrecord = Ext.MessageBox.show({
title:'INFO',
msg: 'Success...',
closable: true,
modal: false,
iconCls: 'msg_success',
icon: Ext.MessageBox.INFO
});
},
failure: function(){
var windowInfoErrorEdit = Ext.Msg.alert({
title: 'Error',
message:'Error...!',
icon: Ext.Msg.ERROR,
button: Ext.Msg.CANCEL,
buttonText:{
cancel: 'Close'
},
});
}
}); //sync

Set badge text after store load with Sencha Touch

I can get the count of items after loading a store and I want to know how and where to update the badge text for the button in the tabbar in the current view.
Here I have my view panel and I think that I could set the badge text in the initialize function:
Ext.define('connect.view.InProgressPanel', {
extend: 'Ext.NavigationView',
xtype: 'inprogressPanel',
requires: [
'connect.view.inprogressleads.InProgressList'
],
config: {
itemId: 'inprogressPanel',
title: 'Leads In Process',
iconCls: 'team',
items:[{
title: 'Leads In Process',
xtype: 'inprogressList'
}]
},
initialize: function( eOpts ) {
var store = Ext.getStore('InProgressLeads');
store.on('load', function () {
var listCount = store.getCount();
console.log(listCount);
// set the badge here
});
}
});
And here I define the button for the panel in the main view:
{
id: 'lipPanel',
title: 'Leads In Process',
iconCls: 'team',
items: [{
xtype: 'inprogressPanel'
}]
},
I have read that I could give a button an ID and then I could use the ID to get the reference to the button, yet I've not found any way to specify the ID of a button when I define it this way in the main panel. Or is there another way to get the button and set the badge text?
Update: Here is a way to set the badge:
<code>
store.on('load', function () {
var listCount = store.getCount();
var apptabbar = Ext.getCmp('ext-tabbar-1');
var tab = apptabbar.down('.tab[title=Leads In Process]');
tab.setBadgeText(listCount);
});
</code>
Try this:
Ext.getCmp('lipPanel').setBadgeText(listCount);
Get a reference to the tabbar and then get a reference to the button by its name.
var apptabbar = Ext.getCmp('ext-tabbar-1');
var tab = apptabbar.down('.tab[title=Leads In Process]');
tab.setBadgeText(listCount);

Adding a button and navigating between views

1.) I need to add 2 buttons, one below another. My working so far is demonstrated below; It only shows one button, but how can i add another button with a different button image below this button ?
2.) When the user clicks a button, i need to navigate to another screen. How can i do this ?
I need the equivalent of the following objective-c code ?
View1 *view1 = [[View1 alloc] initWithNibName:#"View1" bundle:nil];
[self.navigationController pushViewController:View1 animated:YES];
3.) How can i add a navigation Bar (equivalent to the navigation bar shown in iPhone)
The code for the 1st question;
{
items:[
{
xtype:'button',
text: 'Submit',
ui:'confirm',
handler: function(){
var values = Ext.getCmp('contactForm').getValues();
Ext.Ajax.request({
url: 'http://loonghd.com/service/',
failure: function (response) {
//do something
}, success: function (response) {
// do something
}
});
}
}
]
}
1) For getting two buttons one below the other, you can add two separate buttons (with different ui property) as childs of a form panel. I think, this is what you need.
Just like this,
....
....
items : [
{
xtype:'button',
text: 'Submit',
ui:'confirm', // makes the button color as green
handler: function(){
var values = Ext.getCmp('contactForm').getValues();
Ext.Ajax.request({
url: 'http://loonghd.com/service/',
failure: function (response) {
//do something
},
success: function (response) {
// do something
}
});
}
},
{
xtype:'button',
text:'Second button',
ui:'decline', // makes the button color as red.
listeners : {
tap : function() {
Ext.Msg.alert('You just clicked Second button');
}
}
}
]
....
....
2) 3) For your 2nd and 3rd question, navigationview is the solution.
Solution posted by M-x is great, but it's very advanced level example & also difficult to understand at first instance.
Here's an easy solution of navigatioview from Sencha Docs.
//create the navigation view and add it into the Ext.Viewport
var view = Ext.Viewport.add({
xtype: 'navigationview',
//we only give it one item by default, which will be the only item in the 'stack' when it loads
items: [
{
//items can have titles
title: 'Navigation View',
padding: 10,
//inside this first item we are going to add a button
items: [
{
xtype: 'button',
text: 'Push another view!',
handler: function() {
//when someone taps this button, it will push another view into stack
view.push({
//this one also has a title
title: 'Second View',
padding: 10,
//once again, this view has one button
items: [
{
xtype: 'button',
text: 'Pop this view!',
handler: function() {
//and when you press this button, it will pop the current view (this) out of the stack
view.pop();
}
}
]
});
}
}
]
}
]
});
Maybe a navigation view will work for you? It's the same idea but it's like starting with a UITableView:
http://docs.sencha.com/touch/2-0/#!/example/navigation-view
In the app/controller/Application.js, when you tap on a contact, the detail view gets pushed. All the source is in the examples directory.
onContactSelect: function(list, index, node, record) {
var editButton = this.getEditButton();
if (!this.showContact) {
this.showContact = Ext.create('AddressBook.view.contact.Show');
}
// Bind the record onto the show contact view
this.showContact.setRecord(record);
// Push the show contact view into the navigation view
this.getMain().push(this.showContact);
},

How to push Ext.Panel when row selected on Ext.List in Sencha Touch 2.0?

Given a simple Ext.List like the one in the Sencha docs, how can I make a new Panel or Carousel get "pushed" onto the screen when I click on one of the names?
http://docs.sencha.com/touch/2-0/#!/guide/list
I'd like to be able to have a button to navigate back to the main screen too.
You can achieve this using Ext.navigation.View. Here is a very simple application demonstrating this:
Ext.setup({
// onReady is when we can start building our application
onReady: function() {
// Create the view by just adding a config block into Ext.Viewport.
// We give it a reference of `view` so we can use it later
var view = Ext.Viewport.add({
// Give it an xtype of `navigationview` so it knows to create a NavigaitonView
xtype: 'navigationview',
// Define the list as its only item
items: [
{
xtype: 'list',
// Give it a title so the navigation view will show it
title: 'List',
// `itemTpl` is the template for each item in the list. We are going to create a store
// with a bunch of records, which each have a field called `name`, so we use that in our
// template
itemTpl: '{name}',
// Define our store
store: {
// Define the fields that our store will have
fields: ['name'],
// And give it some data for each record.
data: [
{ name: 'one' },
{ name: 'two' },
{ name: 'three' }
]
},
// Now we add a listener for the `itemtap` event, which is fired when a user taps on an item
// in this list. This event is passed various arguments in the signature, but we only need the
// record
listeners: {
itemtap: function(list, index, target, record) {
// now we have the record from the store, which was tapped. we now want to push a new view into
// the navigaitonview
view.push({
// Give it an xtype of panel
xtype: 'panel',
// Set the title to the name field of the record
title: record.get('name'),
// And add some random html
html: 'This is my pushed view!'
})
}
}
}
]
});
}
});
I've added inline comments so you know what is going on.
I also suggest you to ask questions over on the Sencha Forums as you will probably receive a much quicker response.

Sencha Touch nested list detailed page view

I have the following nested list (only on item in at present to make testing easier).
It works ok, but how can I display a normal page view that has html within it or loads the html page in.
var data = {text: 'Top List',
items: [{
text: 'List item',
items: [{text: 'Selected Page'}]
}]
};
Ext.regModel('ListItem', {
fields: [{name: 'text', type: 'string'}]
});
var store = new Ext.data.TreeStore({
model: 'ListItem',
root: data,
proxy: {
type: 'memory',
reader: {
type: 'tree',
root: 'items'
}
}
});
var nestedList = new Ext.NestedList({
fullscreen: true,
displayField: 'text',
title: 'Theatres',
store: store
});
App.views.Pastcard = Ext.extend(Ext.Panel, {
title: "past",
iconCls: "add",
items: [nestedList]
});
Ext.reg('HomeAbout', App.views.Pastcard);
SO want the user selects the 'Selected Page' item it opens the the detailed view page and html information, preferably from an external source to limit the amount of code on one page.
EDIT
I think i can try and be a little clearer.
Below is my nested list.
var data = {text: 'My List',
items: [{
text: 'First List Item',
items: [{text: 'Sub list one'}, {text: 'Sub list Two'}]
},
{
text: 'Second List Item',
items: [{text: 'Sub list one'},{text: 'Sub list Two'}]
}
]
};
When me / the user clciks on the lsit and gets to the sublist then clicks on the list item called say "Sub list Two" then at the moment it opens to a blank page as there are no more lists, but instead I woudl liek to dispaly a normal page with details on, that can scroll and everything.
At the moment I dotn need to worry about loading in my json dynamiocally as I woudl liek to get a working model before I move on to that side of it
Thsi is not a phonegap app but a standard web app to be view online via mobiles.
* Edn of Edit **
Thanks
To use external source use a store with ajax proxy check this http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Store.
To display HTML you can use just html: '<h1>Selected Page</h1>', styleHtmlContent:true,
instead of text:'Selected Page'
The best way is to load JSON objects from:
var myStore = new Ext.data.Store({
model: 'User',
proxy: {
type: 'ajax',
url : '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
then instead of html or text property use a template to display it:
tpl:[
'<h4>Email</h4>',
'<tpl for="emails">',
'<div class="field"><span class="label">{type}: </span>{value}</div>',
'</tpl>'
]
Check this tutorial http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap/ and the API docs http://dev.sencha.com/deploy/touch/docs/ for more information.
Update
To the last items i.e. to the sub lists add this leaf: true then have add a handler fir onItemDisclosure to the list. You can get the record clicked as first argument passed to the event. Then you can use that object to display it on a different panel.
You can still use the tutorial above, just substitue the code where the contacts are fetched from the phone with some static data.
From that tutorial this is the part you need
app.views.Viewport = Ext.extend(Ext.Panel, {
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide',
initComponent: function() {
//put instances of cards into app.views namespace
Ext.apply(app.views, {
contactsList: new app.views.ContactsList(),
contactDetail: new app.views.ContactDetail(),
contactForm: new app.views.ContactForm()
});
//put instances of cards into viewport
Ext.apply(this, {
items: [
app.views.contactsList,
app.views.contactDetail,
app.views.contactForm
]
});
app.views.Viewport.superclass.initComponent.apply(this, arguments);
}});
This is the main panel where the list and the details panel are contained. You handle the onItemDisclosure event on the list, get the record that was clicked on, update the details panel with that data and the switch to that panel with
app.views.viewport.setActiveItem(
app.views.contactsList, options.animation
);