I want the simplest possible solution for editing a value in a slickgrid using a standard html select list.
There are lots of answers here on stackoverflow all of which tell you to implement your own SelectCellEditor. Here are some examples:
Slickgrid, column with a drop down select list?
SlickGrid select editor
slickgrid custom dropdown editor
But these examples are all in javascript and are therefore a little verbose.
So I am going to answer my own question with a stripped-down CoffeeScript version. It works fine for simple select lists and is easy to extend when you want to get fancy.
A Simple SlickGrid SelectCellEditor in CoffeeScript
class SelectCellEditor
last=undefined
constructor:(#args) ->
options = #args.column.options.split(",")
#select=$("<select/>")
.append("<option value=\"#{o}\">#{o}</option>" for o in options)
.appendTo(#args.container)
.focus()
loadValue: (item) ->
last = item[#args.column.field]
#select.val last
serializeValue : -> #select.val()
destroy : -> #select.remove()
focus : -> #select.focus()
isValueChanged : -> #select.val() isnt last
validate : -> {valid: true, msg: null}
applyValue : (item, state) -> item[#args.column.field] = state
Usage
Using the slickgrid columns definition, the SelectCellEditor is applied via the editor attribute with the list of select items supplied using an options attribute, as shown below:
columns = [
// Other slickgrid columns ...
{
id : "colour",
name : "Colour",
field : "Colour",
options : "Red,Green,Blue",
editor : SelectCellEditor
}
]
Related
The background is I have a custom JSON based language.
Consider the following
In file 1, I have the following:
[
{
"name" : "abcde",
"source" : "source::abcde",
// other attributes
},
{
"name" : "qwerty",
"source" : "source::qwerty"
// other attributes
},
]
In file 2, I have the following:
abcde.json
{
"name" : "abcde"
// properties related to it
}
querty.json
{
"name" : "querty"
// properties related to it
}
Now, I want to build an extension/ grammar such that when a visitor uses Ctrl + click on source::abcde, it takes them to abcde.json.
I am wondering how to achieve through a VS code extension. I dont have a lot of expertise in this area.
I took a look into https://marketplace.visualstudio.com/ , could not find one directly. I have 10000+ such definitions, it is becoming very hard to maintain and update these.
Any help on how to achieve this? or some pointing blogs would be really helpful
I'm doing some research on cloud firestore using flutter. Currently I'm looking into querying in cloud firestore. I got a basic idea of how to query like say in the screenshot of the database given below :
The 2nd (Some Dumb Shit) and 3rd (Some Good Shit) projects belong to the field "Hardware" ..... So if I want to search a project with respect to its field ..... I'll do something like this :
databaseReference.collection("Projects").where("Field",isEqualTo: "Hardware")
But say if I want to search projects based on the name of the members ( Referring to the screenshot above ..... I need to search of a project where a name "Sarvesh Dalvi" is present inside the "Members" field). How am I supposed to write a query in this case.
Note :
Name ("Sarvesh Dalvi") is present inside this heirarchy :
DocumentID(eg : "Some Dumb Shit") / Array("Members") / Map({Name : __ , MemberRef :__});
Thanks in advance for the help.
Update :
I learned how to access an array by doing something like this :
Future<dynamic> getUserProjectFromDatabase(String username)
{
return databaseReference.collection("Projects").where("Members",arrayContains: {"Name" : username}).getDocuments().then((value){
print(value.documents.length);
value.documents.forEach((element) {print(element.data);});
});
}
But this works if the Map only contains :
{"Name" : username};
But in my case my Map is something like this :
{
"Name" : username,
"MemberRef" : /*Reference to a Document*/
};
[Refer to the screenshot posted above]
I only want to query for the Name inside the map and not the MemberRef...... so how can I query something like :
Future<dynamic> getUserProjectFromDatabase(String username)
{
return databaseReference.collection("Projects").where("Members",arrayContains: {"Name" : username,"MemberRef" : /* can be anything */}).getDocuments().then((value){
print(value.documents.length);
value.documents.forEach((element) {print(element.data);});
});
}
There is no way to query for just the member name in your current data structure.
You have two main options:
If you also know the MemberRef for the member, you can query with array-contains: where('Members', arrayContains: {'Name':'New User','MemberRef':'value of memberref'}). This works because array-contains can check if the array contains the complete value that you specify.
If you don't know the MemberRef subbfield, then you'll need to change your data model to allow the query. I typically recommend creating an additional field with just the member names: MemberNames: ["New User", "Sarvesh Dalvi"]. Then you can use the same array-contains operator, but now on this new field with the simple type: where('MemberNames', arrayContains: 'New User').
Using
Play Framework,
MongoDB
ReactiveMongo Play JSON library
So in MongoDB; imagine that I have a collection for a league of teams. Each document represents a team's attributes, e.g.
"_id" : ObjectId("59ea36d3fdc2ce3d73c4be96"),
"name" : Team 1,
"stats" : {
"goalsScoredThisSeason" : 17,
"goalsConcededThisSeason" : 6,
"avgTicketPrice" : 74.0,
"thisSeasonFormArr" : [
"W",
"L",
"D",
...
]
...
I'm using scala forms to create input boxes, fill values from my collection (when editing fields), etc. I am able to do so with all of these except for the JsArray. There is a feature which creates the right amount of input boxes for the field array (repeated values) but I would prefer to have all of the values in a single input box, e.g.
W, L, D, ...
This is my case class (using automated mapping):
case class FormData(_id: Option[BSONObjectID], name: String, stats: Option[Stats])
case class Stats(goalsScoredThisSeason: Int, goalsConcededThisSeason: Int, avgTicketPrice: Double, thisSeasonFormArr: Option[JsArray])
So my form looks like this:
object MyForm {
val form = Form(
mapping(
"_id" -> ignored(Option.empty[BSONObjectID]),
"name" -> nonEmptyText,
"stats" -> mapping(
"goalsScoredThisSeason" -> number,
"goalsConcededThisSeason" -> number,
"avgTicketPrice" -> of(doubleFormat),
"thisSeasonFormArr" -> optional(list(text)) // is this correct?
...
)(FormData.apply)(FormData.unapply)
)
}
Can anyone help as to how I would create the suitable reads and writes for thisSeasonFormArr to ensure that the jsArray is converted to a string and vice-versa (so that the array can be mapped to one input box separated by commas). Let me know if you need any more details. Many thanks
Just to update: I now know that mapping the array (of strings) within the form is done like this "thisSeasonFormArr" -> optional(list(text)); ensuring that within the case class we have thisSeasonFormArr: Option[List[String]]. This allows to iterate through the List in the (Play) template to create multiple input boxes as mentioned earlier. So the only issue is to understand what would need to be done to have one input box containing all of the values of the array concatenated (separated by a comma) - being able to map them to the Scala Play form; in order to both read and write the content.
I'm using JSTree to display a small Windows Explorer-like appearance, everything is perfect but I have to implement sorting option also, is there anyway that I can have my tree sorting order dynamically changed? For example I can have a button that allows user to sort contents based on name (asc or desc), size, change date or even type. How can I perform it?
I think there is something wrong with JSTree sort plugin, or at least I cannot understand how it works!
This is what I do in order to change sort based on user interaction:
treeInst = $('#divWindowsExplorer').jstree(true);
var root = treeInst.get_node('j1_1');
$.jstree.defaults.sort = function (a, b) {
return this.get_text(a) < this.get_text(b) ? -1 : 1;
};
$("#divWindowsExplorer").jstree(true).sort(root, true);
$("#divWindowsExplorer").jstree(true).redraw_node(root, true);
Try with sort options.
$("#plugins5").jstree({
"plugins" : [ "sort" ],
'sort' : function(a, b) {
// you can do custom sorting here
// based on your user action you can return 1 or -1
// 1 show on top -1 for show bottom
}
});
For more info click here
root node doesn't work when we call sort, I did sort my tree dynamically by calling sort and redraw_node function with the id of the first node of my tree instead of root.
Hope this is helpful.
I am attempting to provide an API to search a MongoDB collection on various criteria, including a full-text search. Since this is a Scala project (in Play FWIW), I am using Salat, an abstraction around Casbah.
The following code works fine:
MySalatDao
.find(MongoDBObject("$text" -> MongoDBObject("$search" -> "Vidya")), MongoDBObject("score" -> MongoDBObject("$meta" -> "textScore")))
.sort(orderBy = MongoDBObject("score" -> MongoDBObject("$meta" -> "textScore")))
However, I will eventually need to search on multiple criteria and sort the results by their full-text search score, so I explored Casbah's MongoDBObject query builder functionality (at bottom).
So I tried to replicate the above like this:
val builder = MongoDBObject.newBuilder
builder += "$text" -> MongoDBObject("$search" -> "Vidya")
builder += "score" -> MongoDBObject("$meta" -> "textScore")
MySalatDao
.find(a.result())
.sort(orderBy = MongoDBObject("score" -> MongoDBObject("$meta" -> "textScore")))
This gives the following exception:
com.mongodb.MongoException: Can't canonicalize query: BadValue must have $meta projection for all $meta sort keys
at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:214)
at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198)
at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176)
at com.mongodb.QueryResultIterator.<init>(QueryResultIterator.java:64)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
.
.
I've seen this error before--when I didn't include the score component in the query. But once I did that, it worked (as seen in the first code snippet), and I thought the version with the query builder is equivalent.
For that matter, a call to builder.result().toString() produces this:
{ "$text" : { "$search" : "Vidya"} , "score" : { "$meta" : "textScore"}}
Any help with getting the query builder to work for me would be much appreciated.
In your working query you are passing one DBObject for the "query predicate" and a second DBObject for "fields" or "projection" - find takes a second optional argument indicating which fields to return and in case of $text search, there is a special projection field $meta which allows you to get back the score of the matched document so that you can sort on it.
In your builder attempt you are adding the projection DBObject to the query criteria, and that gives you the same error you saw before when omitting the score component as the second argument to find.
Add MongoDBObject("score" -> MongoDBObject("$meta" -> "textScore")) as the second argument to find like you were doing before, and use builder for combining multiple query criteria.
In simple JSON terms, you are calling find like this:
db.coll.find( { "$text" : { "$search" : "Vidya"} , "score" : { "$meta" : "textScore"}} )
when you really want to call it like this:
db.coll.find( { "$text" : { "$search" : "Vidya"} } , { "score" : { "$meta" : "textScore"}} )