ExtJS combobox jsonDataStore - json

var remoteLookupJsonStore = new Ext.data.JsonStore({
root : 'records',
baseParams : {
column : 'fullName'
},
fields : [
{
name : 'name',
mapping : 'fullName'
},
{
name : 'id',
mapping : 'id'
}
],
proxy : new Ext.data.ScriptTagProxy({
url : 'LookupLoader.ashx'
//url: 'http://tdg-i.com/dataQuery.php' similar data
})
});
var combo2 = {
xtype : 'combo',
fieldLabel : 'Search by name',
forceSelection : true,
displayField : 'name',
valueField : 'id',
hiddenName : 'customerId',
loadingText : 'Querying....',
minChars : 1,
triggerAction : 'name',
store : remoteLookupJsonStore
};
This sample works with the original data store 'http://tdg-i.com/dataQuery.php'. My ashx handler returns data in the same format, but the data is different. Anyhow, when I use my ashx handler, the handler gets invoked, it returns data, but combo always stays in the loading state, and never displays the data.
I am assuming that the problem is with the data I am returning, but its format is fine,the last thing I changed was setting the Content Type
context.Response.ContentType = "application/json";
but I still cannot get this thing to work, any suggestions?
this is data coming from my handler.
({"totalCount": "4","records":[{"id":1,"fullName": "aaa bbb"},{"id":2,"fullName":"cc dd"},{"id":3,"fullName":"ee ff"},{"id":4,"fullName":"gg hh"}]});

Your first record (id 1) is missing "fullName" which makes it invalid JSON -- not sure if that's just an error typing it here or not.

proxy : new Ext.data.ScriptTagProxy({
url : 'LookupLoader.ashx'
//url: 'http://tdg-i.com/dataQuery.php' similar data
})
well looks like for querying same domain, I should be using HttpProxy
so there you have it, that is why it was working with the sample data provided by the web site but not with my local version.

Related

Selected row not highlighted in jqgrid

I have written the function for row selection.It is not highlighting the selected row(sometimes highlighting sometimes other row highlighted) and not displaying the icons the way I have written it. following is the code
multiselect : true,
iconSet: "fontAwesome",
datatype : "json",
loadonce : true,
rowNum : 10,
rowList : [ 10, 20, 30 ],
toppager:true,
pager : '#prowed1',
sortname : 'id',
viewrecords : true,
sortorder : "asc",
editurl : "editGrid.html",
onSelectRow : function(rowId) {
var rowId = jQuery("#list1").jqGrid('getGridParam',
'selarrrow');
if (rowId.length > 1) {
$("#list1_iledit").addClass('ui-state-disabled');
}
},
$("#list1").jqGrid(
"navGrid",
"#prowed1",
{
cloneToTop:true,
formatter : "checkboxFontAwesome4",
addicon:"fa fa-plus ",
add : true,
delicon:"fa fa-trash",
del : true,
searchicon:"fa fa-search",
search : true,
refreshicon:"fa fa-refresh",
refresh : true,
editicon:"fa fa-edit ",
edit : true,
saveicon : 'fa fa-floppy-o',
save : true,
},`{ // edit options
afterSubmit : function() {
location.reload(true);
},
beforeShowForm : function(form) {
$("td .navButton navButton-ltr").hide();
},
closeAfterEdit : true
},
{ // add options
beforeShowForm : function(form) {
$("#buName").removeAttr("readonly");
},
closeAfterAdd : true,
clearAfterAdd : true
},
{ // del options
serializeDelData : function(postdata) {
return {
'buName' : $('#list1').jqGrid('getCell',
postdata.id, 'buName'),
'oper' : 'del'
}
}
}
);` $("#list1").jqGrid('inlineNav', "#prowed1", {
//cloneToTop:true,
//iconSet: "fontAwesome",
add : false,
edit : true,
editicon : 'fa fa-pencil-square-o',
save : true,
saveicon : 'fa fa-floppy-o',
editParams : {
aftersavefunc : function(id) {
jQuery('#list1').jqGrid('setSelection', id, false);
},
},
});`
You should provide the demo, which reproduce the problem. The reason of the most problems with highlighted: wrong input data or wrong colModel. Every row of jqGrid have always id attribute (rowid), which should be part of input data: see here. The id value must be unique. If you have id duplicates then you could problems with selection/highlighting of rows.
If you fill the data from the database than you can use native ids from the tables of the database to build unique rowids. Database tables don't allow id duplicates too.
To be able to edit the data in the database you will need to identify the edited data. Such unique value could be used as the rowid. If you fill the grid by JOIN from multiple tables, than composed id could be used. For example, if you fill the the grid with the data from two tables User and Location then the paar (user_id, location_id) are unique. If both user_id and location_id are numbers, then you can use user_id + "_" + location_id as rowid. The value will be sent to the server during editing and you will have full information to find the data in the tables, which need be modified.
I think that you have problems with unique id in the data. Check that the ids used when you insert data in the grid are unique and you do not have duplicate one.
Kind Regards
In your ColModel make sure the property key:true is only specified once and represents a unique row ID value. See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options
Dumb on my part, but I had the property beforeSelectRow set in the grid code that I had copied from another project. This of course was blocking any selection of a grid row.
beforeSelectRow: function (rowid, e) {
return false;
},

Writing mongoDb queries using mongoose to create node api

I have some mongoDb collections 'classrooms' and 'students' of the form:
Classrooms:
{
"_id" : ObjectId("56c7219dbd5f92cd78ae4b7e"),
"name" : "My Students",
"user" : ObjectId("56c7218cbd5f92cd78ae4b7c"),
"updatedAt" : ISODate("2016-02-19T14:07:25.965+0000"),
"createdAt" : ISODate("2016-02-19T14:07:25.965+0000"),
"students" : [
ObjectId("56dbb26cff34aa686c0d9d25"),
ObjectId("56f7c2bf1982aa9219ae8843")
],
"role" : "user",
"allowDelete" : false,
"__v" : NumberInt(0)
}
Students:
{
"_id" : ObjectId("56dbb26cff34aa686c0d9d25"),
"email" : "1989manjari#gmail.com",
"createdBy" : ObjectId("56c7218cbd5f92cd78ae4b7c"),
"classRoom" : ObjectId("56c7219dbd5f92cd78ae4b7e"),
"mentorEmail" : "gauravatbits#gmail.com",
"studentId" : ObjectId("56ced54303b7cb7b0eda9862"),
"status" : true,
"updatedAt" : ISODate("2016-03-11T15:32:36.806+0000"),
"autoAdd" : true,
"createdAt" : ISODate("2016-03-06T04:30:36.073+0000"),
"__v" : NumberInt(0)
}
My query is:
id_list = db.classrooms.distinct("students");
db.students.find({_id: {$in: id_list}, studentId:{$exists:false}},{email:1, mentorEmail: 1}).pretty()
Now I want to create an endpoint in node api for this response. So i wanted to know how can I write these queries in Mongoose and create endpoint like: app.get('/api/myquery') to get the json result.
P.S. : Is it possible to do this, without creating schema in Mongoose because i also have some collections which have large no. of fields(38 fields). I just want to get some json data by applying queries in already existing collections.
something like this with mongoose
just pseudo code
var model = mongoose.model("collection", mongooseSchema)
app.get('/api/myquery', function(){
model.find({_id : id_list}, "email mentorEmail", function(err, data){
if(err)throw err;
res.json(data) // maybe use JSON.stringify() if didnt get json but that sets application/json in header of HTTP
})
})
You can directly insert jsons in mongoose but you should keep in mind that only that data will be read which are mentioned in the models in mongoose. Do keeping 38 fields is not a problem just insert in directly.

How to save more than one register at once on bookshelf.js

Using the following json:
{
"name" : "Teste",
"username" : "teste1",
"password" : "teste1",
"email" : "teste2#teste",
"photo" : "teste",
"description" : "teste",
"company_posts" : [
{"text": "Oi"},
{"text": "olá"}
]
}
And the following code:
company_posts = req.body.company_posts
delete req.body.company_posts
bookshelf.Model.extend({
tableName: 'companies'
}).forge().save(req.body).then(function(company){
for(var prop in company_posts){company_posts[prop].company_id = company.id}
bookshelf.Model.extend({
tableName: 'companies_posts'
}).forge().save(company_posts).then(function(company_posts){
res.send(company_posts)
})
})
The server returns me:
Unhandled rejection Error: ER_WRONG_VALUE_COUNT_ON_ROW: Column count doesn't match value count at row 1
What's wrong? If I try to insert company_posts[0] it works.
How do I insert all company_posts at once?
Thanks.
My error was trying to use Model instead of an Collection
Instead of:
bookshelf.Model.extend({
tableName: 'companies_posts'
// where I use forge() instead of collection()
}).forge().save(company_posts).then(function(company_posts){
res.send(company_posts)
})
This works fine:
bookshelf.Model.extend({
tableName: 'companies_posts'
//where I use collection() and works fine
}).collection(company_posts).invokeThen('save').then(function(company_posts){
res.send(company_posts)
})

usage of range header in jsonrest for paging

new to DOJO..using JsonRest to get data from database...i have given range to display 0-1000 out of 50000 ...but it is displaying full data......requirement is that when that 1000 loaded while scrolling the next request goes to server and rest of the data will display....
please help i tried a lot ......
my code
myStore = dojo.store.Cache(dojo.store.JsonRest({
target : "myip7080/GridExample/string"
}), dojo.store.Memory());
myStore.query({
start: 0,
count: 1000
}).then(function(results){
alert(results);
});
grid = new dojox.grid.DataGrid({
store : dataStore = dojo.data.ObjectStore({
objectStore : myStore
}),
structure : [ {
name : "SNO",
field : "sno",
width : "100px",
editable : true
}, {
name : "SNAME",
field : "sname",
width : "100px",
editable : true
}, {
name : "SALARY",
field : "salary",
width : "200px",
editable : true
} ]
}, "target-node-id"); // make sure you have a target HTML element with this id
grid.startup();
dojo.query("#save").onclick(function() {
dataStore.save();
});
});
dojo/store/Memory::query() takes two parameters:
An object that queries the data
An QueryOptions object containing the options for this query (optional)
You can query specific entries from your data like this:
myStore.query(
{ name: "John Doe" }
);
//returns all rows with name="John Doe"
You don't have to make a specific query. If you want all your data, just do myStore.query("");
If you want to limit the number of rows shown, you need to add a second parameter to represent your query options:
myStore.query(
{ name: "John Doe" },
{ start: 0, count: 1000 } //return 1000 results, starting at the beginning
);
See the documentation for dojo/store/memory::query().

Filtering a comboxes remote store locally in ExtJs

I have an ExtJs combobox. Its store loaded using JSON (using MyStore class below). I want to load all the values to the store, and then filter them with the text entered in the combo's textfield (preferably using the typeAhead feature).
The problem is that I want to do the filtering on the client side (combo's mode property is 'remote', by default). I don't want my combo to reload its store every time I type something.
How can I do that?
Thanks.
Here's my store class :
MyStore = Ext.extend(Ext.data.JsonStore, {
constructor: function(jsonUrl, storeId, id, description, isAutoLoad, cfg) {
cfg = cfg || {};
GenericStore.superclass.constructor.call(this, Ext.apply({
storeId: storeId,
root: 'result',
url: jsonUrl,
autoLoad: isAutoLoad,
fields: [
{
name: id
},
{
name: description
}
]
}, cfg));
}
});
And the combo :
xtype: 'combo',
fieldLabel: 'The Combo',
width: 150,
store: myStoreData,
valueField: 'id',
displayField: 'name',
minChars : 0,
editable : false,
itemId : 'my-combo'
To achieve this you must:
Construct MyStore class with "isAutoLoad" config option as "true"
In your combobox config set the "mode" config option to "local" (see Built the combo config code bellow for another config)
Here is my short example:
Construct myStoreData variable
var myStoreData = new MyStore({
autoLoad: true, //so the store will load automatically
...any_other_config_option...
});
Built the combo config
{
xtype: 'combo',
fieldLabel: 'The Combo',
width: 150,
store: myStoreData,
// myStoreData is already loaded before as it have 'autoLoad' config set to true
// and act as localstore to populate the combo box item
// when the combo "mode" config set to 'local'
valueField: 'id',
displayField: 'name',
minChars : 0,
editable : true, //before was editable : false,
itemId : 'my-combo',
mode: 'local', // by default this was mode: 'remote'
typeAhead: true // by default this was typeAhead: false
}
You will want to use the store.filter() method. You can use this to use user-entered information to filter your store that the combo box uses. This is taken from the ExtJS API documentation for data.store.
store.filter([
{
property : 'name',
value : 'Ed',
anyMatch : true, //optional, defaults to true
caseSensitive: true //optional, defaults to true
},
//filter functions can also be passed
{
fn : function(record) {
return record.get('age') == 24
},
scope: this
}
]);
In my case I had to add the config option lastQuery:'' to the combo.
explanation : http://progex.wordpress.com/2010/03/26/extjs-combo-dropdown-does-not-filter-on-first-trigger/
Add listener to your store on 'load' event, do filtering, by removing or flagging records, if removing it is clear load to combo component, if flagging you need to recognize those flaggs in combo and display or not...
It hard to go with more details if I do not see your code for store and combo, so I can give you only general idea