Multisort/Sort grid with AjaxStore - oracle

i need to implement the multisort in grid that populate from a Ajax Store, but i have also a problem with the simple sorting of column.
This is my store:
dsUser = Ext.create('Ext.data.Store', {
model: 'user',
pageSize: defPagSize,
totalProperty: 'totalCount',
autoLoad: {start: 0, limit: defPagSize},
remoteSort: true,
proxy: {
type: 'ajax',
enablePaging:true,
url: '<c:url value="/queryForList.action?query=User.getUsers"/>',
reader: {
type: 'json',
root: 'list',
totalProperty:'totalCount'
}
}
});
Anytype of help is usefull.
Thanks.
EDIT:
Now i re-write the old logic of sorting in my application..At this moment i find anyone can help me to post and modify grid for posting an array of (property:'', direction:'') and mantain the icon on the grid to select. (sorry for my english)

The proxy is merely sending through the sortParam and value in a structure that is usable in JS...e.g., a JSON-encoded array of objects ([{"property":"email","direction":"DESC"}]).
When you receive this request server-side, you'll absolutely need top parse apart the sort order object and convert it to a string that your DB can understand. Using the raw value from the query string in your DB will not work, nor was it intended to work like that.
When I do this, it's typically like this:
Receive request
Search for sort order param in query string
Decode the JSON string into an object in my server-side app's language
Iterate over the array of sorters and build a "sort" string
Send parsed sort string along to the DB query

Related

ckan datastore_search API with multiple filters

I'm calling this dataset:
http://data.edinburghopendata.info/api/action/datastore_search?resource_id=4cfb5177-d3db-4efc-ac6f-351af75f9f92
with an AJAX call :
var data = {
resource_id: '4cfb5177-d3db-4efc-ac6f-351af75f9f92',
filters: '{"BankTypeNa": "Packaging", "BankTypeNa": "Compost Bins"}',
limit : 4757
};
$.ajax({
url: 'http://data.edinburghopendata.info/api/action/datastore_search',
data: data,
dataType: 'jsonp',
success: function(data) {
markers = data.result.records;
showMarkers();
}
});
which is giving results only for the second filter.
http://data.edinburghopendata.info/api/action/datastore_search?resource_id=4cfb5177-d3db-4efc-ac6f-351af75f9f92&filters={%22BankTypeNa%22:%20%22Packaging%22,%20%22BankTypeNa%22:%20%22Compost%20Bins%22}
Is there a way, or another parameter I could use to get both "Packaging" and "Compost Bins" in my search results?
Would be nice if somebody can prove me wrong, but its not possible. In theory you would just put the two values in an array as the value for the BankTypeNa key, e.g.
filters: '{"BankTypeNa": ["Packaging", "Compost Bins"]}'
But this doesn't work for text columns (an SQL error results). It does work for numeric ones [1]. It would be good to submit an issue on that at github.com/ckan/ckan.
I would use the datastore_search_sql endpoint instead, i.e.
var data = {
"resource_id": "4cfb5177-d3db-4efc-ac6f-351af75f9f92",
"sql": "SELECT * FROM \"4cfb5177-d3db-4efc-ac6f-351af75f9f92\" WHERE \"BankTypeNa\" LIKE 'Packaging' OR \"BankTypeNa\" LIKE 'Compost Bins'",
"limit": 4757
};
[1] CKAN: delete a list of records within the DataStore in a single query

extjs store with ajax serving multi read requests

Unanswered: store ajax serving multi read requests (best practice question)
Hi, im trying to understand the proper design concept of Store proxies using the Ajax api config and have a question on how this should be done.
suppose i have a store which has a server proxy using the Ext.data.proxy.Ajax class and i have an api with the following:
proxy: {
type: 'ajax',
api: {
read: 'some/something/list.json',
create: 'some/something/insert.json',
update: 'some/something/update.json',
destroy: 'some/something/destroy.json'
}
}
now suppose my read is triggered by a search button and when i have a blank text box and click search it makes a request through the read api to retrieve the list.json. but i want to have another read as part of the same store / api to read individual records say something like this:
read: 'some/something/<field_value>.json'
my proxy read is already assigned to the list.json but i want to allow the same store proxy to be able to read from individual record searches also. granted that i cant have two read statements in my proxy. how would I go about writing this?
help me understand? maybe my server controller has to be able to determine by keyword #PathVariable if path is list i.e .json then call the list db query otherwise if .json then run the individual search query through the db.?? and if so what would be the read: url?
whats the best way to design and build this?
Thanks in advance
If you want to read single record instead of defining proxy in store you should do it in Model and then call load on model itself something like below.
Ext.define('app.model.User', {
{
fields: [
{ name: 'LoginUserId', type: 'string' },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' }],
proxy:
{
type: 'rest',
url: '/User',
reader:
{
type: 'json',
root: ''
}
}
});
var user = Ext.ModelMgr.getModel('app.model.User');
user.load(123, {
success: function(userObj) {
}
});

mongoose Is there any difference of performance between subdocument and global in this case?

case1
var MessageSchema = new Schema({
text: {type: String, required: true}
});
var UserSchema = new Schema({
..
messages: {type: [MessageSchema], required: false}
});
UserSchema.find({_id:id},'messages',function(err, messages){
// case 1
});
vs
case2
var MessageSchema = new Schema({
text: {type: String, required: true},
userId: {type:Schema.Types.ObjectId, required: true}
});
MessageSchema.find({userId:id}, function(err, messages){
//case 2
});
I just know How mongodb manipulates these two method.
I presuming you are comparing approaches for finding all documents for a user.
In the first case the _id will be indexed automatically so the find will be fast and the messages will be loaded when the user document is.
In the second case assuming you add an index on message userID then the find will lookup the userID in the index and load all documents that match the userID.
So if you are optimizing for the find and access messages, the first case should always be faster.
However, if you are optimizing message add and you have a large number of messages and new ones are added frequently, in the first case the user document will be growing and moving. It may hit document size limits. A bigger document is being saved.
For more detail, look at this guide which has a good discussion of the tradeoffs between references and embedded documents.
http://docs.mongodb.org/manual/MongoDB-data-models-guide.pdf
I hope this helps.

jqGrid multipleGroup send query to server

I have a jqGrid with the following pager
.navGrid('#pager-mm',{add:false,edit:false,del:false,search:true,view:true},
{},{},{},
{multipleSearch:true,multipleGroup:true,showQuery: true},
{})
When I build a complex query having nested AND and OR groupings, jqGrid builds the correct query as a string on the client-side. Rather than rebuilding the same query on my server writing extra code, I would like to send the correctly built client-side query as a string to the server. However,
beforeSumbit:function()
is not being triggered when I search. How can I send this custom string to my server?
I don't full understand what you really want. By default the filters will be send to the server as filters parameter. Nevertheless you can use onSearch callback for example to access to the searching filter. You can use
var filters = $(this).jqGrid("getGridParam", "postData").filters;
to get filters property of the postData.
UPDATED: I would never ever trust the fragment of SQL statement created on the client side. If you use the SQL fragment which sent from the client in the server code you allow in the way automatically SQL Injection. If security play some role in your application you should not use SQL statement created by jqGrid.
Nevertheless if your question have pure theoretical nature you can get the SQL statement displayed in the searching dialog using toSQLString method of the searching filter. The corresponding code could look like the following
grid.jqGrid('navGrid', '#pager', {edit: false, add: false, del: false}, {}, {}, {}, {
multipleSearch: true,
multipleGroup: true,
showQuery: true,
recreateFilter: true,
onSearch: function () {
var $filter = $("#" + $.jgrid.jqID("fbox_" + this.id)),
sql = $filter.jqFilter('toSQLString');
alert(sql);
}
});
The corresponding demo you will find here. By the way you don't need to use showQuery: true to be able to use toSQLString method.

In ExtJS, How can I list multiple returns from JSON data in a field set?

Ok, I am semi-new to ExtJS, and I am building a program that has "inputs" that are listed in a grid, and in my DB these inputs can be linked to "symptoms".
I am trying to create a function that will take in the id of the input and grab all of the symptoms from the database that are linked to that symptom, and list them in a field set.
It works fine when I click on an input that is only linked to one symptom, but if the input is linked to more than one symptom, then the error says.. "invalid property id"
This is what I have for my function.
function listSymptoms(inputID){
Ext.Ajax.request({
url: "../../inc/project4.php?list=symptoms",
reader: new (Ext.data.JsonReader)({
root: "symptoms",
inputid: "id"
}),
params: {
inputid: inputID
},
method: "POST",
success: function (f, a){
var jsonData = Ext.util.JSON.decode(f.responseText);
symptomsFieldSet.body.update(jsonData.data.name);
},
failure: function (f,a){
Ext.Msg.alert('There was a problem opening your message.');
}
});
}
I have the inputID for the function being passed in when the user clicks on one of the inputs that are held inside the grid.
I believe that my problem has something to do with this line..
symptomsFieldSet.body.update(jsonData.data.name);
I am just stumped on how to handle this. Do I need to create a data store like I have for grids? Or is there an easier way to do this?
ANY help is appreciated! thanks in advance.
I think you need to rethink the structure of your JSON response object. You can send this in your JSON response to your request. If you are using Ext.util.Ajax calls instad of a form, you'll need to decode this JSON response string using the util method Ext.util.JSON.decode(). Check out the API Documentation
{
success: true,
msg: {text: 'this can be used for error message handling' },
data : [
{id:1,
chiefComplaint: 'head hurts',
symptoms: [
{symptomID: '740.1', text: 'Headache'},
{symptomID: '12352135'. text: 'and so on'}
}
]
]
}

Resources