In my jqGrid I have a column that has this format: '1.234,678'. I want to sort this column, and I am using this code:
{name:'ZMENG_SOR_VRKME', index:'ZMENG_SOR_VRKME', width:'5', align:'right', sorttype:'number' }
Sorting doesn't work. I think that it is not considering .(dot) as thousands, for examples if I have 21,000 - 991,000 - 1.188,000. The results is: 991,000 - 21,000 - 1.188,000.
How can I solve this?
If I understand your problem correctly you should change the format of data filled in the grid. You should use pure numbers as the input and use formatter: "number" to include thousands separator in the number. It will be the best way to solve your problem in my opinion. You can use correct language file grid.locale-XX.js the thousands separator will be used corresponds the locale. Alternatively you can use decimalSeparator and thousandsSeparator of formatoptions to specify your custom decimal and thousand separators.
Alternatively you can either provide unformatter (unformat function described here) which converts the text displayed in the cell to the number. I think it should work.
One more possibility is usage of custom sorting. You need define sorttype as function which would be return "normalized" version of the data. The "normalized" data will be used instead of original data during sorting. See the answer and this one for code examples.
UPDATE: Free jqGrid provides some standard templates like template: "integer", number: "number", template: "integerStr", number: "numberStr" and other. Thus one can use
{name: "ZMENG_SOR_VRKME", width: 50, template: "numberStr" }
which would be equivalent to the usage of
{name: "ZMENG_SOR_VRKME", width: 50,
formatter: "number", align: "right", sorttype: "number",
searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] } }
Related
I am using RAML 0.8 and I am defining a query string parameter.
the value for the querystring should be a comma separated list of predefined values
So I have used enum to define the list of acceptable values to use
sort:
description: Comma separated list of stock item properties to sort on.
enum: ['status', 'orderType', 'stockType', 'model', orderNumber']
example: 'orderType,status'
However with the example, I am getting this warning
value should be one of 'status', 'orderType', 'stockType', 'model', 'orderNumber'
I would prefer if possible to get rid of this warning for the example. With RAML 0.8 is this even possible, or should I just ignore it as its only a warning and not an error
The warning is valid. An enum type will only expect one of the possible value. If you need to send an array of those values like: ?sort=status,orderType Then you will need to use a pattern. The example below uses regex to allow a comma seperate list of values. And the specific enum values that can be used are in the pattern.
#%RAML 0.8
title: enum-list
version: v1
protocols: [ HTTP ]
mediaType: application/json
traits:
sortable:
queryParameters:
sort?:
type: string
pattern: ^(\s?[<<fieldset>>,]+\s?,)*(\s?[<<fieldset>>,]+)$
example: 'status,orderType'
/api:
displayName: api
get:
is: [ sortable: { fieldset: status|orderType|stockType|model|orderNumber } ]
As described in the documentation of kendo UI I can affect the possible filter operators with this construct:
filterable: {
operators: {
string: {
isempty: "Is empty",
isnotempty: "Is not empty",
startswith: "Starts with",
contains: "Contains",
}
},
},
With that lines included in my columns definition, I get this four operators in the dropdown to select for filtering. But only "Is empty" works correctly. For the other three options I get no results.
If I delete these lines from the column definition of my grid I get the whole options from filterable.operators.string. When I select one of the four options, shown above, all works fine and the result is correct.
Why is there a different behavior between the default operators for a column and when disabling some of them? And how can I get the correct behavior for just the four operators?
Try putting the startswith filter option first like this:
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
isempty: "Is empty",
isnotempty: "Is not empty",
contains: "Contains",
}
}
}
I did some testing with this example and if I didn't have startswith as first filter option then it would behave like you described. Otherwise it worked.
I am stuck here - last thing to get done before going production.
The date coming from oracle is on the following format: "8/14/2012 10:46:48 AM"
I am using the following on the jqgrid:
{ name: 'CreationDate', index: 'CreationDate', formatter: 'date', formatoptions: { 'srcformat': 'ISO8601Long', 'newformat': 'm/d/Y - g:i A' }, sorttype: 'date', width: 95, align: 'right', resizable: false },
I have the following displaying on the grid: "08/14/2012 - 10:46AM"
The problem is when I try to use the advanced filter it doesn't work. My guess is because of the time, any suggestions on how to solve this?
UPDATE
Oleg, I copied the code you posted with your changes and still nothing. I am using the advanced filter. Thanks for all your help, I really, really appreciate it. I wish I could send you some beer to Germany :o)
I think the main problem is that you use g format inside of newformat which are not currently supported in jqGrid for the local filtering/searching. You can try to use H format instead. Alternatively you can use the fix which is described in the answer.
UPDATED: The demo shows that one can use Advanced Searching dialog with formatter: 'date', formatoptions: { 'srcformat': 'ISO8601Long', 'newformat': 'm/d/Y - g:i A' } after applying the fix which I referenced. You can just try the demo and input the same data (10/04/2012 - 5:55 PM) which I used on the picture below. You have to see the following results:
UPDATED 2: During preparing of another demo for you I found one more bug in internal parseDate function. The problem is that the current implementation of parseDate function works correct only if the date which are need be parsed contain the same elements as specified the format. For example the date 10/04/2012 will be incorrect parsed using 'm/d/Y - g:i A' format. To fix the bug one can include the line
if(typeof date[k] === "undefined") { continue; }
as the first line of the body of the loop. The fixed version of jquery.jqGrid.src.js you can get here.
In the demo I use multipleSearch: true option of jqGrid searching. As the result one can specify the interval of dates like
10/04/2012 <= x <= 10/05/2012
The corresponding Searching Dialog will look like on the picture below and you will be able to filter by intervals of dates
When I am using multiple grids on the same page, or over my entire website, is there any way to abstract out the setup of common grid components? Ex the colModel section, or other components that would be the same between two grids, while giving me the option to make each grid unique, Ex in name, caption, etc.
Basically what this comes down to is I want to avoid the wall of text that comes with the setup of multiple grids that are highly similar.
I was able to achieve some of what I was looking for.
I was able to take the largest chunk of repeated code, the colModel:[..] and turn that into a variable and then call on it.
Ex
var colModelForReuse = [{name: 'exName', index: 'exIndex' ..... },
{.......................................}];
and then later in my Grid setup
colNames: [ 'exName', .....],
colModel: colModelForReuse,
pager: pagerName,
...
Yes, you could create a function that creates your actual grid, and then pass options to it to control the aspects that are different between each grid. A nice way to pass the arguments is to use jQuery.extend, which allows you to easily provide default argument values.
For example:
function myFunction(options) {
options = jQuery.extend(
{
myOption1: 'Default Vaule',
myOption2: 'Default Vaule',
},
options || {});
...
}
I am trying to set-up the jquery validation plugin and one of my inputs requires a number within the range of -121 and -123.
I have tried using the range() method :
$("#myform").validate({
rules: {
field: {
required: true,
range: [-121, -123]
}
}
});
However it doesn't allow any numbers to validate. I have tried using max/min as well but they too don't seem to work on negative numbers. Am I missing something?
Thanks
Does the smaller number need to be first? If so, you want range: [-123, -121] instead.
$.validator.addMethod('inputClassName',
function (value) {
return (Number(value) >= -123 && Number(value) <= -121);
}, 'Enter a number between -121 and -123');
You could add this custom validator method, just replace the inputClassName