Cannot seem to populate combo box remotely in Extjs - combobox

I've tried all manor of things to get this to populate the combo drop-down box.
When typing, say "Apple", it appears to be loading the data but, nothing ends up in the drop down box. Firebug shows the data has been loaded. So, where am I going wrong? Thanks.
Ext.create('Ext.form.field.ComboBox', {
fieldLabel: 'Basket',
emptyText : 'Type a fruit name',
queryMode : 'remote',
minChars : 3,
fields : ['id', 'name'],
store : {
proxy: {
type: 'jsonp',
callbackKey: 'method',
url: 'http://www.comparetrainfares.co.uk/train_scripts/data.php',
reader: {
root: 'items'
},
}
},
needleKey : 'query',
labelKey : 'id',
label : 'name',
displayField : 'name',
width : 260,
forceSelection: true,
renderTo : query1,
});
<?php
header('Access-Control-Allow-Origin: *');
//header('Content-Type: application/json; charset=utf8');
//header('Content-Type: application/x-json');
// http://www.comparetrainfares.co.uk/train_scripts/data.php
$output = array();
$output[] = array('id' => '1', 'name' => 'Apple');
$output[] = array('id' => '2', 'name' => 'Banana');
$output[] = array('id' => '3', 'name' => 'Orange');
$output[] = array('id' => '4', 'name' => 'Lemon');
$objects = array('items' => $output);
echo json_encode($objects);
?>

You are using a jsonp proxy. This is not the default ajax way of loading the store. The php script should be receiving a function name from the 'callback' parameter sent to the php script and then the returning data should be in a format like this:
callback({"items":[{"id":"1","name":"Apple"},{"id":"2","name":"Banana"},{"id":"3","name":"Orange"},{"id":"4","name":"Lemon"}]})
And remember to replace 'callback' with the name of whatever string is being sent in the callback parameter.

This is what I get from FireBug when I type the word "Appl" into the combo box. I know the data coming back is different from what I'm typing but, I still don't get anything even when I enter something which should match.
Under the 'Params' tab I see:
_dc 1361011625341
callback Ext.data.JsonP.callback1
limit 10
page 1
query appl
start 0
The 'Response' tab shows:
{rows:[{"id":"1","genre_name":"Comedy"},{"id":"2","genre_name":"Drama"},{"id":"3","genre_name":"Action"},{"id":"4","genre_name":"Mystery"}]}
The 'JSON' tab shows:
Sort by key
rows
[Object { id=
"1"
, genre_name=
"Comedy"
}, Object { id=
"2"
, genre_name=
"Drama"
}, Object { id=
"3"
, genre_name=
"Action"
}, Object { id=
"4"
, genre_name=
"Mystery"
}]
0
Object { id=
"1"
, genre_name=
"Comedy"
}
1
Object { id=
"2"
, genre_name=
"Drama"
}
2
Object { id=
"3"
, genre_name=
"Action"
}
3
Object { id=
"4"
, genre_name=
"Mystery"
}

Related

How to display array data in Yii2 GridView using ActiveDataprovider?

In my db,
"email" : [
"amnop#mailinator.com",
"abc#mail.com"
],
When I print_r($model->email),
it shows
Array ( [0] => amnop#mailinator.com [1] => abc#mail.com )
In my GridView,
<?= GridView::widget([
'dataProvider' => $dataProvider,
----
'columns' => [
-----
'price',
[
'attribute' => 'email',
'value' => function($model) {
//I need help here... I prefer any foreach function
}
],
-----
]
?>
I have to display all the emails in the same column. How to do this?
Edit
I use ActiveDataprovider as I'm getting the values from my db.
Depending on what you want to achieve, you can just implode emails array:
[
'attribute' => 'email',
'value' => function($model) {
if (is_array($model->email)) {
return implode(', ', $model->email);
}
return $model->email;
}
],
assuming you an array as
$data = [
['email' => 'amnop#mailinator.com'],
['email' => 'abc#mail.com'],
...
['email' => 'youremail100#mail.com'],
];
you can use an ArrayDataProvider
$provider = new ArrayDataProvider([
'allModels' => $data,
'pagination' => [
'pageSize' => 10,
],
'sort' => [
'attributes' => [ 'email'],
],
]);
send the data provider to the as usual
so in gridview you can use ,
<?= GridView::widget([
'dataProvider' => $dataProvider,
----
'columns' => [
-----
'price',
[
'attribute' => 'email',
'value' => function($model) {
//I need help here...
}
],
-----
]
?>
you can take a look at yii2 guide https://www.yiiframework.com/doc/guide/2.0/en/output-data-providers
and doc https://www.yiiframework.com/doc/api/2.0/yii-data-arraydataprovider

How can I show attribute value with check Box in Yii 2 GridView

i like to put mission_id in checkbox
$req = 'select c.mission_id as mission_id, c.user_id as user_id from order c';
$dataProvider = new SqlDataProvider([
'sql' => $req,
]);
return $this->render('factures', [
'dataProvider' => $dataProvider,
]);
in _index.php
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'mission_id',
'user_id',
],
]); ?>
This it's ok, but when i use checkbox, it s KO : Trying to get property of non-object
[
'attribute' => 'id',
'format' => 'raw',
'value' => function($data) {
return '<input type="checkbox" name="chk_group" value="'.$data->mission_id.'" />Mission : '.$data->mission_id;
},
],
Your help please
a some response : Trying to get property of non-object with :
[
'attribute' => 'id',
'format' => 'raw',
'value' => function($model) {
return '<input type="checkbox" name="chk_group" value="'.$model->mission_id.'" />Mission : '.$model->mission_id;
},
],

Issue regarding angular js and setting ng class dynamically

i am new in angular. so i am tying to set class dynamically from my controller class. my program is working but right class is not getting attached. i am not being able to capture where is the problem in code. please see my code and js fiddle and tell me where is the problem for which right class is not getting attached with html element.
<div ng-app="myApp">
<ul ng-controller="MyController">
<li ng-class="setColor(item.businessTime,item.name)" ng-repeat="item in products">{{item.name}} — {{item.price}} — {{clsName}} — {{diff}}</li>
</ul>
</div>
the problem list in setColor() function
var myApp = angular.module('myApp', []);
myApp.controller('MyController', function MyController($scope) {
$scope.dbTime=moment('12:05:05','HH:mm:ss');
$scope.diff='';
$scope.clsName='';
$scope.setColor = function(businessTime,name) {
//alert('businessTime '+businessTime);
//alert('dbtime '+$scope.dbTime);
var diff =$scope.dbTime.diff(businessTime, 'minutes')
//alert(diff);
$scope.diff=diff;
if(diff < 60)
{
alert(name+' clsRed '+diff);
$scope.clsName="clsRed";
return "clsRed";
}
else if(diff > 60 )
{
alert(name+' clsYello '+diff);
$scope.clsName="clsYello";
return "clsYello";
}
else if(diff > 200)
{
alert(name+' clsGreen '+diff);
$scope.clsName="clsGreen";
return "clsGreen";
}
}
$scope.products = [
{
'name' : 'Xbox',
'clearance' : true,
'price' : 30.99,
'businessTime':moment('06:05:05','HH:mm:ss')
},
{
'name' : 'Xbox 360',
'clearance' : false,
'salesStatus' : 'old',
'price' : 99.99,
'businessTime':moment('04:15:22','HH:mm:ss')
},
{
'name' : 'Xbox One',
'salesStatus' : 'new',
'price' : 50,
'businessTime':moment('12:10:22','HH:mm:ss')
},
{
'name' : 'PS2',
'clearance' : true,
'price' : 79.99,
'businessTime':moment('06:25:22','HH:mm:ss')
},
{
'name' : 'PS3',
'salesStatus' : 'old',
'price' : 99.99,
'businessTime':moment('08:11:22','HH:mm:ss')
},
{
'name' : 'PS4',
'salesStatus' : 'new',
'price' : 20.99,
'businessTime':moment('19:41:22','HH:mm:ss')
}
]
})
js fiddle https://jsfiddle.net/tridip/czjo9f1m/1/
please help me to capture the problem. alert is showing setcolor function return right class name but different class is getting attached with html element.......why? thanks

Sencha touch 2.2 sql proxy not inserting data

I successfully tried sencha touch app example showed here
They are using store proxy type as localstorage, its working good and then i changed the proxy type to sql as shown below
Ext.define('notesApp.store.Notes', {
extend : 'Ext.data.Store',
requires : 'Ext.data.proxy.Sql',
config : {
model : 'notesApp.model.Note',
proxy : {
type : 'sql',
database: "SqlProxyTest",
table: "Notes",
id : 'notes-app-store'
},
sorters : [{property : 'dateCreated', direction : 'DESC'}],
grouper : {
sortProperty : 'dateCreated',
direction : 'DESC',
groupFn : function(record) {
if(record && record.data.dateCreated) {
return record.data.dateCreated.toString();
}
return '';
}
}
}
});
There is no error.
I can insert data and i can see the record in list view, but chrome resource showing "The Node table is empty".
If i refresh the browser the record is gone from the list.
Am i missing anything or is it right way to use sql proxy in sencha touch ?
If you have change your model (add a field) you have to drop the table and recreate it.
And when you add a new row on your datastore be sure to put all fields.
Example if i have a model with firstName, lastName, email :
// This one is not added cause email is absent
Ext.getStore('Users').add([{
firstName: 'Toto',
lastName: 'test',
}]);
// This one is added
Ext.getStore('Users').add([{
firstName: 'toto',
lastName: 'test',
email : 'toto#test.te'
}]);
The mistake i did was, i created id for the record i am trying to insert as they showed in that demo example, when i changed below model from
Ext.define("NotesApp.model.Note", {
extend: "Ext.data.Model",
config: {
idProperty: 'id',
fields: [
{ name: 'id', type: 'int' },
{ name: 'dateCreated', type: 'date', dateFormat: 'c' },
{ name: 'title', type: 'string' },
{ name: 'narrative', type: 'string' }
]
}
});
to
Ext.define('notesApp.model.Note', {
extend : 'Ext.data.Model',
config : {
fields : [
{ name : 'dateCreated', type : 'string', dateFormat : 'D'},
{ name : 'title', type : 'string'},
{ name : 'narrative', type : 'string'}
],
validations : [
{type : 'presence', field : 'dateCreated'},
{type : 'presence', field : 'title', message : 'Please enter a title for the note!'}
]
}
});
Everything works fine.

ExtJS 4.1 TreeStore doesn't load with association

I have a TreeStore, which works fine, but every node has some nested data, so I made a new model for it and used the hasMany association. But now the store loads nothing anymore. When I look into the records in the load event, they're empty, but the browser tells me the Ajax request delivered everything like before.
This is what the node data looks like, when it comes from the server:
{
"path": "KEY_518693",
"name": "KEY_518693",
"data": [
{
"branch": "KEY_518693",
"primnav": "ETC",
"X": 29261,
"Y": 96492
},
...
],
"children": [ ... ],
...
}
These are my model definitions:
TreeNode:
{
extend : 'Ext.data.Model',
requires: [
'DataRecord',
'Ext.data.association.HasMany'
],
fields : [
{ name: 'id' , type: 'string', mapping: 'path' },
{ name: 'text', type: 'string', mapping: 'name' },
...
],
hasMany : {
model: 'DataRecord',
name : 'data'
}
DataRecord:
{
extend: 'Ext.data.Model',
fields: [
{ name: 'branch' , type: 'string'},
{ name: 'primnav', type: 'string' },
{ name: 'X' , type: 'int' },
{ name: 'Y' , type: 'int' }
]
}
When I remove the association, the tree loads without problems. When I add data to the fields it gets parsed into the tree, but as "raw" object and not as model instance.
Please note that DataRecord has no field called treenode_id - so your hasMany association isn't complete. See docs for more info.
My approach had 2 problems.
The name of the association should not be 'data' or the records wont get loaded at all.
The primaryKey of the association has to be set right, in my case 'branch' was right

Resources