Extjs- Grid column sorting case insensitive - sorting

I am having a grid populated with search results. The sorting seems to be working fine if all the values in each column are numbers or if all of them are in the same case(upper or lower). But some of the columns in my grid like firstname and lastname are a mix of uppercase, lowercase and empty values. When I click on that particular header for sorting purpose, these values seems to be sorted as case sensitive. The uppercase values come one by one, then there are a mix of empty values and then the lowercase values. I want this sorting to be done as case insensitive alphabetically. I think extjs sorts these values based on the ascii values. Is there any way I can overwrite this functionality and where should I be doing that.
For example, I have some values like james, JAMESON and ROBERT. When I click on top of the header, if it ascending, I should be getting james, JAMESON and Robert and all the empty/null values together at the top or bottom. But that is not happening. I am getting some empty values on the top and then JAMESON, james, empty value again , ROBERT followed by empty/null values. How can I make sure all the null values are grouped together and the sorting should be case insensitive.
{
header: "User Last Name",
width: 170,
dataIndex: 'userLastName'
},
{
header: "User First Name",
width: 170,
dataIndex: 'userFirstName'
},
Thanks,

On the field in your model, define a sortType,
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Field-cfg-sortType
either as a function or as one of the predefined strings:
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.SortTypes
I would guess that asUCText would be a good start, but I don't know what happens to null values there...

var itemsPerPage = 10; // set the number of items you want per page
var data = {
"success" : true,
"users" : [{
"id" : 1,
"name" : 'ed',
"email" : "ed#sencha.com"
}, {
"id" : 2,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 3,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 4,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 5,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 44,
"name" : '1',
"email" : "tommy#sencha.com"
},
{
"id" : 45,
"name" : '2',
"email" : "tommy#sencha.com"
},
{
"id" : 11,
"name" : 'Ed',
"email" : "ed#sencha.com"
}, {
"id" : 12,
"name" : 'apple',
"email" : "tommy#sencha.com"
},
{
"id" : 13,
"name" : 'Apple',
"email" : "tommy#sencha.com"
},
{
"id" : 14,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 15,
"name" : 'tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 21,
"name" : 'Ed',
"email" : "ed#sencha.com"
}, {
"id" : 22,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 23,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 24,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
{
"id" : 25,
"name" : 'Tommy',
"email" : "tommy#sencha.com"
},
]
}
Ext.apply(Ext.data.SortTypes, {
asPerson : function (name) {
// expects an object with a first and last name property
console.log("Test");
return name.toUpperCase() + name.toLowerCase();
}
});
var store = Ext.create('Ext.data.Store', {
autoLoad : true,
fields : [{
name : 'name',
sortType : 'asPerson'
}, {
name : 'email'
// sortType set to asFloat
}
],
pageSize : itemsPerPage, // items per page
data : data,
proxy : {
type : 'memory',
enablePaging : true,
reader : {
type : 'json',
root : 'users',
successProperty : 'success'
}
},
sorters : [{
property : 'name',
direction : 'ASC'
}
],
});
//Ext.Ajax.request({
// loadMask: true,
// url: 'app/data/users.json',
//
// success: function(resp) {
// // resp is the XmlHttpRequest object
// var options = resp.responseText;
//
//
//
// store.loadData(options);
// }
//});
//
//
Ext.define('AM.view.user.list', {
extend : 'Ext.grid.Panel',
alias : 'widget.userlist',
title : 'All Users',
initComponent : function () {
Ext.create('Ext.grid.Panel', {
title : 'My Test Demo',
store : store,
columns : [{
header : 'ID',
dataIndex : 'id'
}, {
header : 'Name',
dataIndex : 'name'
}, {
header : 'Email',
dataIndex : 'email',
flex : 1
}
],
width : 350,
height : 280,
dockedItems : [{
xtype : 'pagingtoolbar',
store : store, // same store GridPanel is using
dock : 'bottom',
displayInfo : true,
pageSize : 5,
}
],
renderTo : Ext.getBody()
});
this.callParent(arguments);
}
});

In ExtJS5 I add a transform to the sorter, e.g.
sorters: {
transform: function(item) {
return item.toLowerCase();
},
property: 'category_name'
}

Related

How to get current sort field in kendo grid?

I'm beginner...
I'm using kendo-grid with Jquery.
I want to get current sorted field in kendo-gird.
I found this.
console.log(grid.dataSource._sort[0].dir);
console.log(grid.dataSource._sort[0].field);
Can I find alternative way?
this is my code.
var dataSource = new kendo.data.DataSource({
transport : {
read : {
type : 'post',
dataType : 'json',
contentType : 'application/json;charset=UTF-8',
url : cst.contextPath() + "/watcher/kendoPagination_statsErrorHistoryRetrieveQry.htm",
data : param
},
parameterMap: function (data, opperation) {
return JSON.stringify(data);
}
},
schema : {
data : function(data) {
return data;
},
total : function(response) {
return response.length > 0 ? response[0].TOTAL_COUNT : 0;
}
},
pageSize : cst.countPerPage(),
serverPaging : true,
serverSorting : true
});
var columns = kendoGridColumns();
$("#grid")
.kendoGrid({
dataSource : dataSource,
sortable : {
mode : 'multiple',
allowUnsort : true
},
columns : columns.error()
selectable : 'row',
scrollable : true,
resizable : true,
}));
How can I get current sorted field name?
Avoid using private fields. The DataSource sort method is the official way to get the current sort state:
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-sort
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
],
sort: { field: "age", dir: "desc" }
});
var sort = dataSource.sort();
console.log(sort.length); // displays "1"
console.log(sort[0].field); // displays "age"

how can i get object key with distinct values from array of objects in elasticsearch using aggregation?

i have products collection(index) with following documents :
{ name : 'test1',
attributes : [ {name :"color" , value : 'red'}, {name : 'size' , value : 's'}, {name : 'type' , value : 'simple'}]
}
{ name : 'test2',
attributes : [{name : 'size' , value : 'm'}]
}
{ name : 'test3',
attributes : [ {name :"color" , value : 'green'}, {name : 'size' , value : 's'}]
}
{ name : 'test4',
attributes : [ {name :"color" , value : 'red'}]
}
How can i get output like below using elastic search aggregation ?
Output :
{
attributes : {
color : [ {value : 'red', count : 2}, {value : 'green', count : 1} ],
size : [ { value : 's', count : 2}, {value : 'm', count : 1}],
type : [ {value : 'simple', count : 1}]
}
}

Kendo Grid - Grouping and logic

I have a question about the Kendo Grid and grouping - I'd like to include some logic when it comes to grouping a grid. I need to group addresses by state, and if state is empty, then group by country. Is this doable? Thanks.
You could create a hidden column that has state is available otherwise country, and then set the datasource to group by that column:
var jsondata = [
{City : "Houston",State : "Texas",Country : "USA"},
{City : "New York",State : "New York",Country : "USA"},
{City : "Austin",State : "Texas",Country : "USA"},
{City : "London",State : "",Country : "UK"},
{City : "Manchester",State :"",Country : "UK"},
{City : "Paris",State : "",Country : "France"}
];
for (var i=0; i < jsondata.length; i++){
var stateCountry = jsondata[i].State ? jsondata[i].State : jsondata[i].Country;
jsondata[i].Group = stateCountry;
}
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: jsondata,
schema: {
model: {
fields: {
City: { type: "string" },
State: { type: "string" },
Country: { type: "string" },
}
}
},
group: {
field: "Group",
dir: "asc"
}
},
groupable: false,
scrollable: true,
columns: [
{ field: "City" },
{ field: "State" },
{ field: "Country" },
{ field: "Group", title: "State/Country", hidden: true }
]
});
});
DEMO

jqgrid inlinenav save/edit not available with hidden id column

I have a jqgrid with an id that is a db sequence and thus the user doesn't need to see it. When the column is marked as 'hidden : true' the inlinenav edit is not clickable and the save won't save. It works fine when I comment that out.
$("#grid_d").jqGrid(
{
url : "${pageContext.request.contextPath}/testjson?id=0",
datatype : "json",
colNames : [ "id", "analyte","units" ],
colModel : [ {
name: 'id',
index: 'id',
hidden : true,
editable : true
}, {
name : 'analyte',
index : 'analyte',
editable : true
}, {
name : 'unit',
index : 'unit',
editable : true
} ],
sortname : 'id',
pager : '#pager_d',
viewrecords : true,
editurl : "${pageContext.request.contextPath}/editjson"
});
$("#grid_d").jqGrid('navGrid', "#pager_d", {
edit : false,
add : false,
del : true
}, {}, // edit options.
{}, // add options.
{
reloadAfterSubmit : false,
afterSubmit : deleteMessage,
msg: "Delete selected analyte(s)"
}, // del options.
{}, // search options.
{} // view options.
);
$("#grid_d").jqGrid('inlineNav',"#pager_d");

How to send data from jsp page to controller using jqgrid in spring

var pid = $('#byId').val();
jQuery("#patient").jqGrid({
mtype: 'GET',
url : "totalPatientList.html",
postData :{pid:pid},
datatype : "json",
colNames : [ 'Patient Id', 'Name', 'BirthDate', 'Address','City','Mobile' ],
colModel : [ {
name : 'patientId',
index : 'patientId',
width : 55
}, {
name : 'name',
index : 'name',
width : 200
}, {
name : 'birthdate',
index : 'birthdate',
width : 100,
editable : true
}, {
name : 'address',
index : 'address',
editable : true,
width : 80
}, {
name : 'city',
index : 'city',
editable : true,
width : 80
}, {
name : 'mobile',
index : 'mobile',
editable : true,
width : 80
} ],
rowNum : 10,
rowList : [ 5, 10, 30 ],
pager : '#pager',
sortname : 'id',
viewrecords : true,
sortorder : "desc",
caption : "Search Patient's List",
width : 800,
cellEdit : true,
});
I have a code like above.
I want to send pid from this JSP page to controller.I am getting pid , but when I reload my web page. I want it without reloading the page when i click the button.
How can I do that?
plz plz help me....
You should use the "function" style of postData:
url: "totalPatientList.html",
postData: {
pid: function () {
return $('#byId').val();
}
}
In the case the value for the pid parameter will be new evaluated on every request to the server. See the answer for more details. In the way you can send multiple parameters to the server by including multiple methods in postData object.

Resources