jsPDF: how to add and/or align two distinct tables next to each other (side by side) - jspdf

I have two tables and I need to put them next to each other.
For example purposes, I used the same dataset, but the table on the left side might have a few more rows.
I found several examples, but I couldn't find a way to get what I expected.
jsPDF v2.3.1
const doc = new jsPDF('p', 'mm', 'A4');
doc.autoTable({
head: [['ID', 'Name', 'Country']],
body: [['1', 'Simon', 'Sweden'], ['2', 'Karl', 'Norway']],
margin: {left: 120}
});
doc.autoTable({
head: [['ID', 'Name', 'Country']],
body: [['1', 'Simon', 'Sweden'], ['2', 'Karl', 'Norway']],
margin: {
// top: 80, // test
right: 120
},
});

After two days of research, so far, apparently the best way was to use a parent table (template) and nest the two tables in each column (td) of the parent table, using the autoTable.didDrawCell() method.
const doc = new jsPDF('p', 'mm', 'A4');
doc.autoTable({
html: '#table-parent',
didDrawCell: function (data) {
// to nest a child table within the first cell of the first row
if (data.row.index === 0 && data.column.index === 0) {
doc.autoTable({
head: [["LEFT", "Two", "Three", "Four"]],
body: [
["1", "2", "3", "4"],
["1", "2", "3", "4"],
["1", "2", "3", "4"],
["1", "2", "3", "4"]
],
startY: data.cell.y + 2,
tableWidth: data.cell.width,
theme: 'plain', // plain | grid
});
// to nest a another child table within the second cell of the first row
if (data.row.index === 0 && data.column.index === 1) {
doc.autoTable({
head: [["RIGHT", "Two", "Three", "Four"]],
body: [
["1", "2", "3", "4"],
["1", "2", "3", "4"],
["1", "2", "3", "4"],
["1", "2", "3", "4"]
],
startY: data.cell.y + 2,
tableWidth: data.cell.width,
theme: 'plain', // plain | grid
});
}
}
}
});
// DOWNLOAD
// doc.save('table.pdf');
// PREVIEW
window.open(doc.output('bloburl'));

Related

Kusto Query: Join multiple tables

‎
TablesA, TableB, TableC
After joining the tables: TableA, TableB, TableC using Kusto Query how to show the value of column: IsPriLoc in the column: PriLoc and IsSecLoc in SecLoc. Below is the expected result
ExpectedResult
I made a couple of assumptions (regarding data types for example) but this query delivers the required results:
Link to execute on Kusto help cluster
let A = datatable (GUID_PK: string, Name: string, Desc: string) [
"1", "Test1", "Desc1",
"2", "Test2", "Desc2",
"3", "Test3", "Desc3",
"4", "Test4", "Desc4",
"5", "Test5", "Desc5",
"6", "Test6", "Desc6"
];
let B = datatable (GUID_FK: string, PriLoc: string, SecLoc: string) [
"1", "PriLoc1", "SecLoc1",
"3", "PriLoc3", "SecLoc3",
"5", "PriLoc5", "SecLoc5",
];
let C = datatable (GUID_FK: string, IsPriLoc: string, IsSecLoc: string) [
"2", "TRUE", "FALSE",
"4", "FALSE", "TRUE",
"6", "TRUE", "FALSE",
];
let BC = B
| union (
C
| project GUID_FK, PriLoc=IsPriLoc, SecLoc=IsSecLoc);
A
| join BC on $left.GUID_PK == $right.GUID_FK

XCODE Filter Table View Cells with multipe checkboxes

I'm currently developing an app in Xcode. Within this app I want to give the user the possibility to filter the content of Table View Cells (objects) by multiple checkboxes [see picture 1].
Every object thats shown in the Table View has 8 properties which have the value 1, 2 or 3. The checkboxes shown in the filter area are in relationship with these 8 properties.
Like:
Checkbox1 = prop1
Checkbox2 = prop2
Checkbox3 = prop3
etc..
Objects arrays:
var objects:[Object] = [
Object(name: "Lorem Ipsum", prop1: "3", prop2: "1", prop3: "1", prop4: "1", prop5: "1", prop6: "1", prop7: "3", prop8: "2"),
Object(name: "Lorem Ipsum", prop1: "1", prop2: "1", prop3: "1", prop4: "3", prop5: "1", prop6: "1", prop7: "3", prop8: "2"),
Object(name: "Lorem Ipsum", prop1: "1", prop2: "2", prop3: "2", prop4: "2", prop5: "2", prop6: "1", prop7: "3", prop8: "2"),
Object(name: "Lorem Ipsum", prop1: "2", prop2: "3", prop3: "3", prop4: "1", prop5: "3", prop6: "1", prop7: "3", prop8: "2"),
Object(name: "Lorem Ipsum", prop1: "1", prop2: "3", prop3: "1", prop4: "2", prop5: "2", prop6: "3", prop7: "2", prop8: "1"),
Object(name: "Lorem Ipsum", prop1: "2", prop2: "3", prop3: "1", prop4: "1", prop5: "1", prop6: "1", prop7: "3", prop8: "2")
]
When all checkboxes are unchecked all the objects will show the same default color (blue).
But when one of the checkboxes is checked, the filter needs to change the color of the objects that have the related property to the selected checkbox, as value 2 or 3. When the value is 2 = change to green color, and when the value is 3 = change to purple color.
So for instance; if checkbox2 is selected, all objects with prop2 as 2 or 3 should have a different color [see picture 2]
I did research but couldn't find a way to do it and make it work. If somebody could help, that would be amazing!
EDIT-NOTE: If the user selects two checkboxes, for instance 1 and 2, the objects with value 3 on property 1 or 2 needs to have the color purple, even if they have a value 2 on one of these properties. So value 3 'weighs' more than 2
I would suggest maybe using a dictionary for all the checkboxes. Assign each checkbox a unique tag value (0-7).
let filters: [Int: Bool] = [0: false, 1: false ... 7:0]
When one is selected via a fund didSelect(checkbox: UIButton){ self.tableView.reloadData() }, you would update the corresponding filter by setting self.filters[checkbox.tag] = true.
Then your tableView data items should be filtered by iterating through all the filters and checking if they are true/false before assigning a color for the cell using cellForRow(at: IndexPath).

How to compare 3 json array in ios?

Here are the 3 JSON arrays from different responses.
I just want to print "Name" in case Book which has "size_id" be 1 then print "Name" and "Discripition"
and "Prize" who has category_id & Size_id match in Objective-C (on iOS).
category
[ {
"Category_Id": "1",
" Name": "Books",
}
{
"Category_Id": "2",
" Name": "Dummies",
}
product
[
{
"Sub_Cat_Id": "3",
"Category_Id": "1",
"Size_id": "3",
"Sub_Name": "java",
"Description": "We are introducing new product.",
},
{
"Sub_Cat_Id": "4",
"Category_Id": "2",
"Size_id": "3",
"Sub_Name": "Android",
"Description": "We are introducing new product.",
},
{
"Sub_Cat_Id": "2",
"Category_Id": "1",
"Size_id": "1",
"Sub_Name": "ios",
"Description": "We are introducing new product.",
},
Prize
[
{
"Size_Id": "1",
"pirze": "600 "
},
{
"Size_Id": "2",
" pirze ": "300 "
},
{
"Size_Id": "2",
" pirze ": "800"
}
I suggest transforming this JSON into Foundation's NSArray via NSJSONSerialization's dataWithJSONObject:.
After that just use NSArray/NSDictionary filtering to retrieve your values
I suggest you to create a class for your objects (category, product and prize), so you can create an objects for your readings and add them to a NSArray. Once you've got the objects in the same array you can apply a predicate to that array, in order to choose only the objects you want:
NSArray *objects = ...; // This is the array with your objects
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"(prize.size_id == 1)"];
NSArray *array = [objects filteredArrayUsingPredicate:tiltPredicate]; // This is the array with the objects you want (size_id = 1)

Dynamic nested collapsible set based on dynamic section in jquery mobile

I follow this answer for creating collapsible set. now I want to create nested collapsible set. I have a json like:
[
{
"sid": "26",
"tour_name": "4",
"day": "2",
"time": "16:00",
"main_location": "Madurai",
"sub_location": "Mahal",
"site_link": "www.maduraimahal.com",
"description": "test"
},
{
"sid": "25",
"tour_name": "4",
"day": "2",
"time": "13:00",
"main_location": "Trichy",
"sub_location": "Rockport",
"site_link": "www.rockport.com",
"description": "Test"
},
{
"sid": "24",
"tour_name": "4",
"day": "2",
"time": "12:00",
"main_location": "Madurai",
"sub_location": "Temple",
"site_link": "www.madurai.com",
"description": "Test "
},
{
"sid": "17",
"tour_name": "4",
"day": "1",
"time": "09:00",
"main_location": "Chennai",
"sub_location": "City Centre",
"site_link": "www.wikipedia.com",
"description": "test"
},
{
"sid": "16",
"tour_name": "4",
"day": "1",
"time": "08:00",
"main_location": "Chennai",
"sub_location": "Spencer Plaza",
"site_link": "www.spencer.com",
"description": "test"
},
{
"sid": "15",
"tour_name": "4",
"day": "1",
"time": "07:00",
"main_location": "Chennai",
"sub_location": "Express Avenue",
"site_link": "www.wikipedia.com",
"description": "test"
}]
From this json I want to create collapsible set like following type
day-->First collapsiple
---main_location-- >second collapsiple
---sublocation-->listview
Exmaple
day 1
--Chennai
---expressavenue
---Spencer Plaza
---City Centre
day 2
--Trichy
---Rockfort
-- Madurai
---Mahal
---Temple
I am trying following method but can't group like this
$(document).on('pageshow', '#itienary', function (event, ui) {
$.getJSON('url', function (data) {
var collapsible = [];
var days = [];
var collapsible1 = [];
var mainlocation = [];
$.each(data, function (i, v) {
collapsible.push(v.day);
$.each(collapsible, function (i, v) {
if ($.inArray(v, days) === -1) {
days.push(v);
days.sort();
}
});
});
$.each(days, function (j, main) {
var day = main;
var locations = '';
$.each(data, function (k, val) {
var mainloc = val.main_location;
if (val.day == day) {
collapsible1.push(mainloc);
}
$.each(collapsible1, function (i, v) {
if ($.inArray(v, mainlocation) === -1) {
mainlocation.push(v);
mainlocation.sort();
}
});
});
$.each(mainlocation, function (i, loc) {
var parent = loc;
var elements = '';
$.each(data, function (x, sub) {
var subLoc = sub.sub_location;
var time = sub.time;
var sitelink = sub.site_link;
if (sub.main_location == parent) {
elements += '<li><h2>' + subLoc + '</h2><p><strong>' + time + '</strong></p><p class="ui-li-aside"><strong>Sitelink: ' + sitelink + '</strong></p></a></li>';
}
});
$("#itinerary-list").append($("<div/>", {
"data-role": "collapsible",
"data-iconpos": "left",
"data-collapsed-icon": "arrow-d",
"data-expanded-icon": "arrow-u",
"class": day
}).append($("<h3/>").text("Day " + day)).appendTo($("<div/>"), {
"data-role": "collapsible",
"data-iconpos": "left",
"class": parent
}).append($("<h3/>").text(parent)).append($("<ul/>", {
"data-role": "listview",
"data-theme": "b"
}).append(elements).listview()));
$('#itinerary-list').collapsibleset('refresh');
});
});
});
});
How can I done this?

Rails how to remove obj from that have certain combination?

Example I have this array:
#packages = ["2", ["4", "2", "1"], "4", ["4","2"], ["5", "6"]]
2 and 4 may not be composed
There for ["4", "2", "1"] and ["4,"2"] should be removed from the array
How should it be done?
So the output would be: #packages = ["2", "4", ["5", "6"]]
2 and 4 is just an example. And the number of numbers vary also.
If you want to remove arrays, that have at least 2 elements in common with given do:
#packages = ["2", ["4", "2", "1"], "4", ["4","2"], ["3", "2"]]
#opposites = ["2", "4"]
#packages.reject! { |p| p.is_a?(Array) && (#opposites & p).size >= 2 }
After this #packages => ["2", "4", ["3", "2"]]
The easiest way to see if an Array has both "2" and "4" is to use Array#& (i.e. set intersection):
#packages.reject { |a| a.is_a?(Array) && (a & [ '2', '4' ]).length == 2 }
For example:
>> #packages = ["2", ["4", "2", "1"], "4", ["4","2"], ["5", "6"], ["1", "2"], ["4", "11"], ["2", "2", "4"]]
=> ["2", ["4", "2", "1"], "4", ["4", "2"], ["5", "6"], ["1", "2"], ["4", "11"], ["2", "2", "4"]]
>> #packages.reject { |a| a.is_a?(Array) && (a & [ '2', '4' ]).length == 2 }
=> ["2", "4", ["5", "6"], ["1", "2"], ["4", "11"]]
If you have your reject list in a separate array then the above generalizes quite easily:
rejects = %w(2 4)
#packages.reject { |a| a.is_a?(Array) && (a & rejects).length == rejects.length }
You'd just have to make sure that rejects didn't have any duplicates but you can always add a uniq if you're not sure if rejects has duplicates.
As already commented, you question is not entirely clear. If you just want to remove the Array elements of the main array then you can do.
#packages.reject{|element| element.is_a?(Array)}

Resources