![]() ![]() |
|||||||
|
|||||||
![]() |
|||||||
|
|||||||
User TypesLet new user type is named UserType. It's need to specify the following functions and variables: var USERTYPE_FORMAT = ""; //(*) // Input : data : UserType, // format : String // Output: // if data can't be formatted (for example null) return DEFAULT_RESULT; function formatUserType(data, format) //(*) { return data; } // Input : data : ANY // Output : if data can't be parsed return null; function parseUserType(data) //(*) { return data; //:UserType } //function that compare op1, op2 : UserType function compareUserType(op1, op2) { return result; //-1 (op1 < op2) | 0 (op1==op2) | 1 (op1 > op2) }; Then you can use new user type at the column description. You can also redifine all built-in type, just redefine the format* or parse* function for need type. Important! Please be careful writting type name!Use upper case for all the letters at the format t ype string. At the function names you should use the same letter case as for type name, which is used at the type field. Example code: //Add new type Discount var DISCOUNT_FORMAT = "%"; function formatDiscount(data, format) { return data + " " + format; }; function parseDiscount(data) { if (Undef(data)) return 0; data = parseFloat(data.replace(/[^0 - 9-\ + \.]/ig, '')); if (isNaN(data) || data < 0) data = 0; if (data > 100) data = 100; return new Number(data); }; function compareDiscount(op1, op2) { if (Undef(op1) && Undef(op2)) return 0; else if (Undef(op1)) return 1; else if (Undef(op2)) return - 1; if (op1 > op2) return 1; else if (op1 < op2) return - 1; else return 0; }; //Redefine type Number, it required only integer values >=0 function parseNumber(numVal) { if (Undef(numVal)) return 0; numVal = parseInt(numVal.replace(/[^0 - 9-\ + \.]/ig, '')); if (isNaN(numVal) || numVal < 0) return 0 else return new Number(numVal); }; var gridDef = { ... colDef : [ { title : "Discount", titleClass : "", type : "Discount", width : 0, alignment : "center", compareFunction : compareDiscount, isVisible : true, isReadOnly : false, useAutoIndex : false, useAutoFilter : false }, ... Example - Discount as new usertypeYou can see an example and complete code here - Discount as new usertype [popup] |
|||||||
© CodeThat.com, 2003-2005 |