jQuery DataTables - understanding how data is fed in, mRender/mData..? - datatables

I am struggling with grasping jQuery datatables (v1.10.1 via CDN), and the conventions used in the current version. Various documentation is confusing/lacking in 'complete' examples at best, conflicting at worst.
Please explain the current (v1.10.1) best practices with regards to defining the contents of a field.
I see lots of information about columns/mData/mRender/mDataProp, amongst others and I feel overloaded as to what each one means and/or when each should be used (see the 'research' section below for examples).
Secondly, where do I stand with regards to using dates and "set"/"display"/"filter"/"sort" (assuming that this is the route to take, with mData/mRender)?
Example
EDIT: Here's an example of some data in a fiddle:
var massData = [
{ "Column1": "test1", "Timestamp": "Sun Jul 27 2014 14:42:20 GMT+0100 (GMT Standard Time)", "Date": "18/10/2012" },
{ "Column1": "test2", "Timestamp": "Mon Jul 28 2014 14:42:20 GMT+0100 (GMT Standard Time)", "Date": "18/10/2016" },
{ "Column1": "test3", "Timestamp": "Wed Jul 22 2014 14:42:20 GMT+0100 (GMT Standard Time)", "Date": "18/01/2012" }
];
var keys = ["Column1", "Timestamp", "Date"];
var columns = [];
for (var keyIndex = 0; keyIndex < keys.length; keyIndex++) {
columns.push({
"title": keys[keyIndex],
"data": keys[keyIndex],
"defaultContent": ""
});
}
$('#demo').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>');
$('#example').dataTable({
"data": massData,
"deferRender": true,
"scrollY": 400,
"scrollX": true,
"columns": columns
});
http://jsfiddle.net/2M97f/
Research
I see this question which has code using mRender, though my understanding is that filtering/sorting will use the actual data
I see this example and this documentation which uses aoColumnDefs, aTargets and mData..?
This question has a reply to "Filtering using the rendered text", but uses aoColumnDefs, mDataProp, and a 'renderDate()' function, but does NOT make use of mRender
The documentation for mRender and mData suggests that mRender depends upon mData..
Other documentation suggests fnRender/bUseRendered is deprecated

First of all, you're looking at examples from previous version (which are obvious based on the Hungarian Notation) So any example with mData may work now, but could be rendered unusable once legacy support is removed. While they can give you an idea of a direction to go, it's dangerous to find methods in the old API and then expect them to work as-is with 1.10. There is a version converter document that helps a lot to understand equivalents between old and new.
My preference is to use this example that uses the "columns" definition to specify the data field easily. You can also quickly and easily define things for each column there, such as searchable, title, visible, etc. See the API for others.
So, a sample Datatable in my code would look like this:
$('#example').DataTable( {
data: data,
columns: [
{ data: 'keyoffield1', title:'name title', visible:'false' },
{ data: 'keyoffield2', title:'position title' },
{ data: 'keyoffield3', title:'salary title here' },
{ data: 'keyoffield4', title:'office title here' }
]
} );
As for sorting, it's setup to recognize date fields out of the box for you, as you can see in your example (click on the header to change the sort) However, if you want to set default sorts such as asc, desc, etc, that's pretty easily done with columns.sort as you'll see in the API. There is a simple plugin to enhance sorting on fields that may not be formatted in a way that DataTables is built to use.
fnRender is gone, the closest equivalents are explained here. If you ignore those examples and the complaining that happened when it was removed, it's pretty easy to see how Allan was proceeding with the new methods like column.render for example.

Related

How do I join and project a multi-map index?

I'm struggling to get my head around this one and I know the way to do this is through a custom index. Essentially, I have several collections that share some common properties, one of which is "system id" which describes a many-to-one relationship, e.g.
// Id() = "component:a"
{
"Name": "Component A"
"SystemId": "system:foo"
}
// Id() = "resource:a"
{
"Name": "Resource A",
"SystemId": "system:foo"
}
So these are two example objects which live in two different collections, Components and Resources, respectively.
I have another collection called "Notifications" and they have a RecipientID which refers to the Id of one of the entities described above. e.g.
// Id() = "Notifications/84-A"
{
"RecipientID": "component:a",
"Message": "hello component"
}
// Id() = "Notifications/85-A"
{
"RecipientID": "resource:a",
"Message": "hello resource"
}
The query that I want to be able to perform is pretty straight forward -- "Give me all notifications that are addressed to entities which have a system of ''" but I also want to make sure I have some other bits from the entities themselves such as their name, so a result object something like this:
{
"System": "system:foo",
"Notifications": [{
"Entity": "component:a",
"EntityName": "Component A",
"Notifications": [{
"Id": "Notifications/84-A",
"Message": "hello component"
}]
}, {
"Entity": "resource:a",
"EntityName": "Resource A",
"Notifications": [{
"Id": "Notifications/85-A",
"Message": "hello resource"
}]
}]
}
Where I am with it right now is that I'm creating a AbstractMultiMapIndexCreationTask which has maps for all of these different entities and then I'm trying to use the reduce function to mimic the relationship.
Where I'm struggling is with how these map reduces work. They require that the shape is identical between maps as well as the reduce output. I've tried some hacky things like including all of the notifications as part of the map and putting dummy values where the properties don't match, but besides it making it really hard to read/understand, I still couldn't figure out the reduce function to make it work properly.
How can I achieve this? I've been digging for examples, but all of the examples I've come across make some assumptions about how references are arranged. For example, I don't think I can use Include because of the different collections (I don't know how Raven would know what to query), and coming from the other direction, the entities don't have enough info to include or load notifications (I haven't found any 'load by query' function). The map portion of the index seems fine, I can say 'give me all the entities that share this system, but the next part of grabbing the notifications and creating that response above has eluded me. I can't really do this in multiple steps either, because I also need to be able to page. I've gone in circles a lot and I could use some help.
How about indexing the related docs ?
Something like this (a javascript index):
map("Notifications", (n) => {
let c = load(n.RecipientID, 'Components');
let r = load(n.RecipientID, 'Resources');
return {
Message: n.Message,
System: c.SystemId || r.SystemId,
Name: c.Name || r.Name,
RelatedDocId: id(c) || id(r)
};
})
Then you can query on this index, filter by the system value, and get all matching notifications docs.
i.e. sample query:
from index 'yourIndexName'
where System == "system:foo"
Info about related documents is here:
RavenDB Demo
https://demo.ravendb.net/demos/csharp/related-documents/index-related-documents
Documentation
https://ravendb.net/docs/article-page/5.4/csharp/indexes/indexing-related-documents

Zabbix pre-processing item get item within an array with javascript

I don't have any experience with Javascript so I'm reaching out for the community to accomplish the below.
I have a few API calls configured on Zabbix which are working just fine. The thing is, not all of the results within an item is importante for me so I need to grab just what I want out of the array.
I'm using the pre-processing option on Zabbix to grab what I'm after but I can't get the code correct.
For instance, the below is one of the results Zabbix is getting.
[
{
"batteryLife": "15 minutes",
"communityString": "public",
"instanceId": "260596.1",
"instanceName": "UPS-01",
"ipAddress": "10.1.100.44",
"modelNumber": "GXT4-10000RT230",
"name": "UPS-01",
"objectType": "ScUps",
"scName": "pth-pf-04",
"scSerialNumber": 260596,
"serialNumber": "unknown",
"status": "Up",
"statusDescription": "Online",
"type": "Liebert"
}
]
How Can I Use the pre-processing to grab just the "ipAddress" value for instance?
Thanks for the help.
PeteF
You can avoid JavaScript preprocessing where you can use JSONPath preprocessing, see https://www.zabbix.com/documentation/current/manual/config/items/preprocessing/jsonpath_functionality
In your case:
$[0].ipAddress
A useful tool for JSONPath is http://jsonpath.com/
In case someone have the same doubt as I was having here is how I got it working to return the "ipAdress" value
var json = JSON.parse(value);
return json.ipAddress;
In case there are more than one dictionary inside of an array.
var json = JSON.parse(value);
return json[0].ipAddress;

I am facing issue for selenium webdriver script for Goibibo site city selection using xpath/css selector

While selecting city from site using xpath/css selector facing issue let me know solution
List<WebElement> frm=driver.findElements(By.cssSelector("html body div#gi_midcontent.col-md-12.col-sm-12.col-xs-12.pad0 div#gi_mid_in div#viewContainer div#flights-home-view.homeContainer.col-md-12.col-sm-12.col-xs-12.myPropDisplay div.homeContainerInner div#searchWidgetNew.blueBg.homeWidgetWrap.posRel form#gi_search div#searchWidgetCommon div.formWrap.padT15 div#source_st.fl_shAutosgBox.col-md-5.col-sm-5.col-xs-12.autoSuggestBox.marginB10 input#gi_source_st.form-control.inputTxtLarge.fromTxt.posRel"));
Couple of things.
Go through the selenium document here.http://www.seleniumhq.org/docs/03_webdriver.jsp
Read on how to use different locator strategy to identity particular locator.
Don't ask the question just because something is not working,spend some time on that.
Visit this page to understand how to ask question so that you can get answers.
The reason I have mentioned above point is you css locator looks pathetic, also the locator you are trying to identify has both name and id, and if you now how to use locator you could have figure that out.
The selector specified in the problem mixed id and class. However, taking a look at the website, the suggested city list is not offered as a group of input elements but fetched from AJAX.
Sending GET query with Postman tool on this URL and you can get JSON data with a list of objects. The property of json["data"]["r"][index]["xtr"]["cn"] seems a string of "CityName". This API does not require authentication so it can be fetched with Java HttpClient, too.
https://voyager.goibibo.com/api/v1/flights_search/find_node_by_name_v2/?search_query=hint&limit=10
The sample result:
{
"data": {
"r": [
{
"s_sc": 5055001,
"xtr": {
"cn": "Beica",
"cid": "1918715907401915921",
"cc": "ET",
"dis_type": "ldis",
"ar": 0,
"eid": "7717797727439208389",
"cnt_n": "Ethiopia",
"cnt_id": "1871100673297067773",
"dis": 0
},
"iata": "BEI",
"n": "Beica Airport",
"mt": "Beica Airport ### Beica",
"t": "airport",
"_id": "7717797727439208389",
"ct": {
"_id": "1918715907401915921",
"n": "Beica"
}
},
...
]
}
}
Please replace "hint" with your query string, for example, a letter to start with. Also take the note that (page) limit could not be greater than 50 in one query.

Displaying Only Certain Columns/Properties with Keen DataViz

I'm wondering how to display only certain columns on my table when I'm trying to do data visualization. Right now, every time that I do a table, it shows every single property or column. I tried to figure out how to only show certain columns properties by guessing based on the documentation for extraction within the keen.io docs (I've commented out my wrong guess)
var foo = new Keen.Query("extraction", {
eventCollection: "Purchases",
targetProperty: "zip",
// I've commented out line 7 because it doesn't work, it was just my guess on syntax...
// how do I only show certain columns of the table (columns are properties)
// vs. showing the entire table?
// propertyNames: ["zip","businessname"]
filters: [
{
"property_name" : "zip",
"operator" : "eq",
"property_value" : "80016"
},
{
"property_name" : "city",
"operator" : "eq",
"property_value" : "Aurora"
}]
});
client.draw(foo, document.getElementById("chart-09"), {
chartType: "table",
title: "Table"
});
https://gist.github.com/mrtannerjones/ba0cbd7340f2e016fcf2 - here is a link to the above code except on github in case something isn't formatted correctly.
Sorry if this question seems terribly basic or simple, I'm still really new at learning how to code.
Found the fix with a little help from David in the Keen.io Google group. I actually was just missing a comma after the 'property names', but what's more interesting to me is that the data visualization works with both camel case and with underscore separators. property_names and propertyNames both seem to work.

Does the JIRA REST API require submitting a transition ID when transitioning an issue?

If I POST an issue transition like this:
{
"fields" : {
"resolution" : {
"name" : "Fixed"
}
}
}
...I get this error:
{
"errorMessages" : ["Missing 'transition' identifier"],
"errors" : {}
}
This seems to imply that I need to include a transition ID along with my list of changed fields. https://stackoverflow.com/a/14642966/565869 seems to say the same. Fine.
However, transition IDs appear to be global. It's not enough to look up the highest transition ID for this issue and increment it; such an ID is probably in use elsewhere. At some expense, I could get the highest transaction ID used anywhere in the system; this might be 68,000 at this moment. But if I were then to use transaction ID 68,001 there's a real chance that a GUI user would attempt a transition of their own and use this ID before I could.
I could use transaction IDs in the range of 1,000,001 and up, but if the JIRA web GUI uses the highest previously used transaction ID when generating new IDs I'll just collide in this range instead of the 68,000 range. I could use 69,000 and trust that there won't be a thousand transitions in the length of time it takes to get the highest transaction ID.
These both seem terribly clumsy, however. Is there no way to post a transition and let JIRA generate its own unique ID? I don't need to retrieve the generated IDs, I just want to update issues' statuses and resolutions.
You're getting mixed up a bit. So lets see if I can explain it better for you.
To transition a JIRA Issue, you use the Transition ID to identify what transition to apply to the issue. You aren't specifying an ID for a transaction or a transition ID to identify that the transition occurred, JIRA takes care of this for you.
The easiest way to understand it is to see it.
So first you can look at what transitions are available to an Issue by doing a GET to the API Call:
/rest/api/2/issue/${issueIdOrKey}/transitions
Example:
/rest/api/2/issue/ABC-123/transitions
Which will show something like this:
{
"expand": "transitions",
"transitions": [
{
"id": "161",
"name": "Resolve",
"to": {
"description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.",
"iconUrl": "https://localhost:8080/images/icons/statuses/resolved.png",
"id": "5",
"name": "Resolved",
"self": "https://localhost:8080/rest/api/2/status/5"
}
}
]
}
So you can see only 1 transition is available for issue ABC-123 and it has an ID of 161.
If you were to browse to that JIRA Issue through the GUI, you would see only 1 Transition available and it would match the API Call. In fact if you inspected the element you should see it having an a tag and in the href something like action=161
So should you want to transition this issue, you'll need to do a POST to the following URL:
/rest/api/2/issue/ABC-123/transitions
With JSON like this:
{
"update": {
"comment": [
{
"add": {
"body": "Bug has been fixed."
}
}
]
},
"fields": {
"assignee": {
"name": "bob"
},
"resolution": {
"name": "Fixed"
}
},
"transition": {
"id": "161"
}
}
Which uses the transition ID found from the call that shows all transitions. I also update the resolution and assignee and add comments at the same time.
That make a bit more sense?