mixed sorting in extjs grid - sorting

I want to sort a column based on text and numbers.
values i have are sorted like this:
- List:010
- List:100
- List:134
- List:2
- List:204
but what i need is
- List:2
- List:010
- List:100
- List:134
- List:204
the column type i am using is string. i tried to use sortType but that was not working.
{
name: 'listItems',
type: 'string',
mapping: 'listItems'
}

If you are using ExtJS 4.x, you can take advantage of the SortTypes class.
Ext.apply(Ext.data.SortTypes, {
asPerson: function(person){
// expects an object with a first and last name property
return person.lastName.toUpperCase() + person.firstName.toLowerCase();
}
});
Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: [{
name: 'person',
sortType: 'asPerson'
}]
});
More information on the SortTypes doc page.

Related

How to validate array of objects in laravel?

I have an array of objects with different, dynamic parameters. And I'm trying to find a way to validate it based on the object type value.
Is there any way to make it with the FormRequest?
[
{
type: “link”,
url: “https://link.com”,
...
},
{
type: “image”,
id: “drre-ggre-765”,
image: “url”
...
}
]

KendoUI Grid: Array as a field

I have a data source, which gets built from a JSON data string, containing a field called Fruit:
[{
... /other entries
fruit: [{
name: 1
}, {
name: 2
}, {
name: 3
}]
}]
I'm using this field in a KGrid, and would like to do a comma seperated list of links, from the names:
1, 2, 3
Currently, I'm hooking into the dataBound function, and build this up individually for the fruit field, is there an easier way to do this with, let's say, a template? I tried to look up information about something similar in the docs, but couldn't find anything pertaining to splitting arrays?
I wouldn't transform the data at the data source. That job is the responsibility of the UI component. Instead move your logic to the column template function of your grid. [ API reference ]
$('#grid').kendoGrid({
columns: [ {
field: 'fruit',
template: function(dataItem) {
var html = [];
for (var i = 0; i < dataItem.length; i++) {
html.push('' + dataItem[i].name + '');
}
return html.join(', ');
}
}],
dataSource: data
});

jqGrid casting data to a String before sort

I'm trying to sort a list of orders based on total money spent on the purchase. The list looks like this (extra fields omitted for clarity):
[
{products:[
{name: 'foo',price:2.53},
{name: 'bar',price:5.74}
]},
{products:[
{name: 'baz',price:6.74},
{name: 'quux', price:7.68}
]}
]
The column definition in question looks like this (with sumPricesOf taking an array similar to the above and returning the total spent):
{
name: 'products',
label: 'Total spent',
index: 'products',
formatter: function(d){return '$'+sumPricesOf(d.products)},
sorttype: 'function',
sortfunc: function(a,b){
return sumPricesOf(a.products) - sumPricesOf(b.products);
}
}
However, if I use console.log(a,b) in the sortfunc, when it gets called a and b are getting passed as strings! The arguments get passed as [object Object],[object Object].
Why can't jqGrid just give me back the data that I passed it?
Strong recomend use sorttype: float option in colModel array.

How to have a numeric text box for editing a cell in a Kendo UI grid?

Looking at the Kendo UI grid demos (ASP.NET MVC CSHTML flavor), when editing a cell that is bound to an numeric value, the input becomes a numerictextbox, but I can't seem to reproduce that behavior (on my side in stays a plain input). There must be something that assigns it the data-role attribute or something, but what is it ?
Thanks,
In order to use the model binding and have Kendo automatically assign the respective control, you need to setup a MVC editor template (http://coding-in.net/asp-net-mvc-3-how-to-use-editortemplates/) , i.e. Views/Shared/EditorTemplates. e.g. to render a Kendo NumericTextBox, create an editor template along these lines:
#model int
#(Html.Kendo().NumericTextBox())
Define the field type as numeric in the schema.
Example: Check UnitPrice or UnitsInStock
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
Kendo provides some templates under shared/EditorTemplates => here is Integer.cshtml template is ther. we can use that to show numeric value in a column. We need to set the EditorTemplateName property on column of the Grid.
EditorTemplateName("Integer") on column.Bound for that column.

Sorting a Column by Default (on load) Using Dojo Dgrid

When loading a dgrid from a dojo store, is there a way to specify a column to be sorted by default.
Say I have 2 columns, Name and Email, I want the name column sorted by default when the grid is first loaded. What I want is the equivalent of the user clicking on the 'Name' header (complete with the sort arrow indicating the sort direction).
Thanks,
John
You can do something like this :
var mygrid = new OnDemandGrid({
store : someStore,
queryOptions: {
sort: [{ attribute: "name" }]
}
// rest of your grid properties
}, "someNode");
dgrid 1.1.0 - set initial/default sort order
var TrackableRest = declare([Rest, SimpleQuery, Trackable]);
var store = new TrackableRest({target: apiUrl, useRangeHeaders: true, idProperty: 'id'});
var grid = new (declare([OnDemandGrid, Selection, Editor]))({
collection: store,
sort: [{"property":"name", "descending": false}],
className: "dgrid-autoheight",
columns: {
id: {
label: core.id
},
category_text: {
label: asset.category
},
name: {
label: asset.model,
},

Resources