jqGrid: Microsoft JScript runtime error: Unable to get value of the property 'integer': object is null or undefined - jqgrid

I get the above exception at this line of code of jqGrid.src.js
fmt = $.jgrid.formatter.integer || {};
I can't for the life of me tell you what that means or why I can't get the damn thing to work. I suspect it has to do with how I am building my json object.
for(int j = rowstart; (j <= rowend && variable.Template.Count > j); j++){
PatientACOModel patMod = variable.Template[j];
var rowData = new{
id = patMod.EncounterId,
cell = new {
MRN = patMod.MRN,
Hospital_Fin = patMod.HospitalFinNumber,
First_Name = patMod.FirstName,
Last_Name = patMod.LastName,
Date_of_birth = patMod.DateOfBirth
}
};
al.Add(rowData);
}
var griddata = new {
total = variable.Template.Count % rows > 0 ? (variable.Template.Count / rows) + 1 : (variable.Template.Count / rows),
page = page,
records = al.Count,
rows = al.ToArray()
};
I have no clue what I am doing wrong? It looks like everything is set up correctly?
UPDATE
This would be the json data that is being sent back to my jqGRid... These are just a small selection of rows, and columns. Am I missing something here?
{"total": 2,
"page": 1,
"records": 15,
"rows": [{
"id": 2148,
"cell": {
"MRN": "840134833",
"Hospital_Fin": "987141516",
"First_Name": "YELLOW",
"Last_Name": "CRAYON",
"Date_of_birth": "\/Date(1253160000000)\/"
}
},
{
"id": 1898,
"cell": {
"MRN": "785528039",
"Hospital_Fin": "6669511596226",
"First_Name": "RAYFIELD",
"Last_Name": "BOYD",
"Date_of_birth": "\/Date(-720298800000)\/"
}
}]}

To eliminate this error, you need to make sure that you are including the localization file
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
before the jqGrid file. That eliminated the problem for me.

Related

elasticsearch sort by price with currency

I have data
{
"id": 1000,
"price": "99,01USA",
},
{
"id": 1001,
"price": "100USA",
},
{
"id": 1002,
"price": "780USA",
},
{
"id": 1003,
"price": "20USA",
},
How I sort order by price (ASC , DESC)
You can alter it a little to parse price to integer and then sort it
You can create a dynamic sort function that sorts objects by their value that you pass:
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
/* next line works with strings and numbers,
* and you may want to customize it to your needs
*/
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
So you can have an array of objects like this:
var People = [
{Name: "Name", Surname: "Surname"},
{Name:"AAA", Surname:"ZZZ"},
{Name: "Name", Surname: "AAA"}
];
...and it will work when you do:
People.sort(dynamicSort("Name"));
People.sort(dynamicSort("Surname"));
People.sort(dynamicSort("-Surname"));
Actually this already answers the question. Below part is written because many people contacted me, complaining that it doesn't work with multiple parameters.
Multiple Parameters
You can use the function below to generate sort functions with multiple sort parameters.
function dynamicSortMultiple() {
/*
* save the arguments object as it will be overwritten
* note that arguments object is an array-like object
* consisting of the names of the properties to sort by
*/
var props = arguments;
return function (obj1, obj2) {
var i = 0, result = 0, numberOfProperties = props.length;
/* try getting a different result from 0 (equal)
* as long as we have extra properties to compare
*/
while(result === 0 && i < numberOfProperties) {
result = dynamicSort(props[i])(obj1, obj2);
i++;
}
return result;
}
}
Which would enable you to do something like this:
People.sort(dynamicSortMultiple("Name", "-Surname"));
Subclassing Array
For the lucky among us who can use ES6, which allows extending the native objects:
class MyArray extends Array {
sortBy(...args) {
return this.sort(dynamicSortMultiple(...args));
}
}
That would enable this:
MyArray.from(People).sortBy("Name", "-Surname");

Rotate when moving three js object from one point to another based on given data

I have three js box object moving from one point to another using given data. I am trying to rotate the object on each chaining. can anybody help me on this.?
Here is the working fiddle
https://jsfiddle.net/geoanas/eywgknt8/12/
var json = JSON.parse('{"items":{ "item_1":{ "value": "50","rotation":"100" }, "item_2":{ "value": "60","rotation":"150" }, "item_3": { "value": "70","rotation":"250" }, "item_4": { "value": "50","rotation":"300" }}}');
var rotation_arr=[0,150,250,300];
var tween = new Array();
var i=0;
for (var key in json["items"]) {
var pos = parseFloat(json["items"][key].value);
scene.add(box);
var targetPosition_temp = new THREE.Vector3(pos, 20, 0);
*var tween_temp = new TWEEN.Tween(box.position).to(targetPosition_temp, 5000);*
tween.push(tween_temp);
if (tween.length > 1) {
tween[tween.length - 2].chain(tween[tween.length - 1]);
}
i++;
}
tween[0].start();

Sorting an array of NSDictionary

I am pulling data from Firebase and in every loop I will get one piece of data in NSDictionary format (e.g. 1st loop I get {Kelvin: 10} , 2nd loop I get {John, 40}, 3rd loop I get {Mary, 27} ,etc)
I created a variable called "namedic" to store the data
var namedic = [NSDictionary]()
I then use an if statement in the loop to catch the data
if let myname = thename["name:"] as? NSDictionary {
//(thename["name:"] prints {Kelvin: 10}
self.namedic.append(myname)
}
I will then get an array of NSDictionaries
[{
"Kelvin" = 10;
}, {
"John" = 40;
}, {
"Mary" = 27;
}]
My question is, how do I sort this array of NSDictionaries in alphabetical order?
What I want is this:
[{
"John" = 40;
}, {
"Kelvin" = 10;
}, {
"Mary" = 27;
}]

SNMP4j agent snmp table

I have created on SNMP agent using snmp4j api but getting issue with snmp table registration
Once i register a table and and rows in table. and after that if i set the values in table all the rows got set with same value.
I have snmp table created from JSON
In below table if i set value
.1.3.6.1.4.1.1.201.6.2. it set the values for all the rows that are registered in below table. Does anyone aware of how to register and set the values properly using snmmpj agent.
{
"tableName": "table1",
"tableId": ".1.3.6.1.4.1.1.201.6.1",
"columns": [
{
"columnName": "column1",
"columnOID": 1,
"dataType": 70,
"accessType": 1,
"defaultValue":0
},
{
"columnName": "column2",
"columnOID": 2,
"dataType": 70,
"accessType": 1,
"defaultValue":0
},
{
"columnName": "column3",
"columnOID": 3,
"dataType": 70,
"accessType": 1,
"defaultValue":0
},
]
}
public static MOTable<MOTableRow<Variable>, MOColumn<Variable>, MOTableModel<MOTableRow<Variable>>> createTableFromJSON(
JSONObject data) {
MOTable table = null;
if (data != null) {
MOTableSubIndex[] subIndex = new MOTableSubIndex[] { moFactory
.createSubIndex(null, SMIConstants.SYNTAX_INTEGER, 1, 100) };
MOTableIndex index = moFactory.createIndex(subIndex, false,
new MOTableIndexValidator() {
public boolean isValidIndex(OID index) {
boolean isValidIndex = true;
return isValidIndex;
}
});
Object indexesObj = data.get("indexValues");
if(indexesObj!=null){
String indexes = data.getString("indexValues");
String tableOID = data.getString("tableId");
JSONArray columnArray = data.getJSONArray("columns");
int columnSize = columnArray.size();
MOColumn[] columns = new MOColumn[columnSize];
Variable[] initialValues = new Variable[columnSize];
for (int i = 0; i < columnSize; i++) {
JSONObject columnObject = columnArray.getJSONObject(i);
columns[i] = moFactory.createColumn(columnObject
.getInt("columnOID"), columnObject.getInt("dataType"),
moFactory.createAccess(columnObject
.getInt("accessType")));
initialValues[i] = getVariable(columnObject.get("defaultValue"));
}
MOTableModel tableModel = moFactory.createTableModel(new OID(
tableOID), index, columns);
table = moFactory.createTable(new OID(tableOID), index, columns,
tableModel);
String[] indexArrString = indexes.split(";");
for(String indexStr: indexArrString){
MOTableRow<Variable> row = createRow(new Integer(indexStr.trim()), initialValues);
table.addRow(row);
}
}
}
return table;
}
First of all, OIDs do not start with a dot (as specified by ASN.1).
Second, you do not seem to use any row index data. Rows are indentified by their indexes. A row index is the instance identifier suffix of a tabular instance OID:
<tableOID>.1.<rowIndex>
The can consists several sub-index values encoded as OIDs.

Removing an elements from basicdblist

Hi i have collection which contains around 200 documents looks like
e.g
"_id": 0,
"name": "Demarcus Audette",
"scores": [
{
"type": "exam",
"score": 30.61740640636871
},
{
"type": "quiz",
"score": 14.23233821353732
},
{
"type": "homework",
"score": 31.41421298576332
},
{
"type": "homework",
"score": 30.09304792394713
}
]
now i wrote code like
DBCursor cursor = collection.find().sort(new BasicDBObject("scores.score":1));
while( cursor.hasNext() )
{
DBobject obj=cursor.next();
BasicDBList list=(BasicDBList) Bobj.get("scores");
// Now here i am getting list of documents which consists of an scores array and i need to remove 3rd elements of it and save collection.... but how to do?
if i use for loop like
for(int i=0;i<list.size();i++)
{
list.remove(2);------ it gives an error here
collection.save(obj);
}
}
Are you sure that you can sort it as 'scores.score'. As 'scores' is a list of objects you cant reference objects inside list using dot notation. Error should be on that line.
Edit:
DBCursor cursor = collection.find();
while ( cursor.hasNext()) {
DBObject dbObject = cursor.next();
BasicDBList dbList = (BasicDBList) (dbObject.get("score"));
//then use java Collections.sort() to sort the List (refer to two methods at the bottom)
dbList.remove(3);
collection.save(dbObject);
}
Use one of the following to sort the DBList
1 . Using Lambda expression
Collections.sort(dbList, (o1, o2) -> Double.compare(((BasicDBObject) o1).getDouble("score"), ((BasicDBObject) o2).getDouble("score")));
or java 7 <
Collections.sort(dbList, new Comparator<Object>() {
public int compare(Object o, Object o2) {
if (((BasicDBObject) o).getDouble("score") >= ((BasicDBObject) o2).getDouble("score")) {
return 1;
}
return -1;
}
});
See this link https://gist.github.com/machadolucas/5188447/raw/e3f5c44c2be756c6087809df63f7ea8f4682ace9/Mongo3_1.java
I`m has been
[some symbol for post this message)))]

Resources