Display Table form with Eloquent Data Laravel - laravel

I have an Object structure that is store in Eloquent Form
{"item_id": "2",
"item_color": "Black",
"item_size": "L",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "M",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "S",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "White",
"item_size": "S",
"item_Quantity": "5",},
What I'm trying to achieve is to combine up all item_quantity which has the same item_id and item_color and Display in Table form like this.
ItemID ItemColor ItemSize Quantity Total
2 Black L-M-S 5-5-5 15
2 White S 5 5
In my research this is the nearest kind of solution but Im having trouble on displaying it in table form
http://stackoverflow.com/questions/23902541/add-array-values-of-same-array-keys-in-session

$items = DB::table('item')
->select(DB::raw("item_id,item_color,GROUP_CONCAT(item_size SEPARATOR '-') as ItemSize,GROUP_CONCAT(item_Quantity SEPARATOR '-') as Quantity,sum(item_Quantity) as TOTAL"))
->groupBy('item_id','item_color')
->get();

Related

foreach item in an array find largest record using mongodbcsharp driver

Suppose there is an document like:
{
"_id": "1cf2080c-ce9a-367b-93ba-dbf7b2bf8a2c",
"template_id" : "1cf2080c-ce9a-367b-93ba-dbf7b2bf8a2c",
"some_value" : 12
}
mapping to a class as Template, and given a templateid array array_id = ["aa", "bb", "cc"]
question: how can I get a Template List using mongodb C# driver2.1 up, which each item in list have largest some_value ?
for example there is a collection:
{"_id": "1", "template_id": "aa", "some_value":1}
{"_id": "2", "template_id": "aa", "some_value":2}
{"_id": "3", "template_id": "aa", "some_value":3}
{"_id": "4", "template_id": "bb", "some_value":4}
{"_id": "5", "template_id": "bb", "some_value":5}
and a template_id_array = ["aa", "bb"]
expect result is:
{"_id": "3", "template_id": "aa", "some_value":3}
{"_id": "5", "template_id": "bb", "some_value":5}
I think it would be some "aggregate" or "map-reduce" like procedure, first match result and then group by template id and then find max somevalue for each group.
I have not tested this but should work with some probable modifications
var result = new List<Template>();
foreach (var element in template_id_array)
{
var filter = builder.Eq("TemplateId", element);
var doc = await collection.Find(filter)
.SortByDescending(x => x.SomeValue)
.Limit(1)
.FirstOrDefaultAsync();
result.Add(doc);
}
Then you can serialize it to the final form:
var expectedResult = JsonConvert.SerializeObject(result);

how to display databse data in table form in laravel5

i have database table data in object form, like this
{"item_id": "1",
"item_color": "Black",
"item_size": "L",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "white",
"item_size": "M",
"item_Quantity": "5",},
{"item_id": "3",
"item_color": "green",
"item_size": "S",
"item_Quantity": "5",},
{"item_id": "4",
"item_color": "yellow",
"item_size": "S",
"item_Quantity": "5",}
i want display the data in table format.i am searching but i can,t find exact solution.
Something along the lines of:
<table>
<thead>
<tr>
<td>Color:</td>
<td>Size:</td>
<td>Quantity:</td>
</tr>
</thead>
<tbody>
#foreach($items as $item)
<tr>
<td>$item->item_color</td>
<td>$item->item_size</td>
<td>$item->item_quantity</td>
</tr>
#endforeach
</tbody>
</table>

jqGrid and jqPivot 4.7: Incorrect names for pivoted columns

This sample uses jqGrid 4.6:
http://jsfiddle.net/aUDHx/1218/
As one can see, regardless of the number of aggregates, the header names are displayed correctly ("A A", "A B", etc.)
However, when I switch to version 4.7, the pivoted columns aren't named correctly when more than one aggregate is used:
http://jsfiddle.net/aUDHx/1219/
If only one aggregate is used, the headers display correctly.
Does 4.7 have a different method of specifying the header names, or is this a bug? If the latter, does an appropriate workaround exist?
This is the code for the yDimension:
yDimension: [{
dataName: 'product',
converter: function (val) {return val.replace(/\s/g, ' ');}
}],
The converter function is used to correctly format the header name. This is not required in 4.7 if you only use one aggregate, but anything more than that causes it to break.
"Gurrido" is now the new name of jqGrid.
The problem is in spaces which you use in names. jqPivot don't support currently spaces in the names. You can fix the problem by replacing the spaces to _ (underscore) for example. I described the workaround here.
By the way Gurrido jqGrid is not the only successor of free open source jqGrid with MIT licence. After starting Gurrido jqGrid some other jqGrid forks of the last free jqGrid is developing. I post my results here. I plan to publish new version probably in the current month. Another fork you can find here. One apply in the fork many changes which I make in my repository, but one make some his own changes too.
UPDATED: The problem with the labels which you described is a bug in jqGrid 4.7. By the way you don't need to use the converter in case of usage spaces in the aggregation values.
I posted the bug fix here in my jqGrid repository. You can see the results on the demo http://jsfiddle.net/OlegKi/b47ocLd7/
The demo uses the following JavaScript code
var mydata = [
{ id: "1", product: "A A", sold: "8", sold2: "8", sold3: "8", emp: "Michelle" },
{ id: "2", product: "A A", sold: "3", sold2: "8", sold3: "8", emp: "Tania" },
{ id: "6", product: "A B", sold: "1", sold2: "8", sold3: "8", emp: "Mark" },
{ id: "3", product: "A B", sold: "5", sold2: "8", sold3: "8", emp: "Tommy" },
{ id: "4", product: "B B", sold: "2", sold2: "8", sold3: "8", emp: "Dave" },
{ id: "5", product: "B B", sold: "5", sold2: "8", sold3: "8", emp: "Carol" }
];
$("#grid").jqGrid("jqPivot", mydata, {
xDimension: [
{ isGroupField: false, width: 40, dataName: "id", label: "ID" },
{ isGroupField: false, width: 80, dataName: "emp", label: "Employee" }
],
yDimension: [
{ dataName: "product" }
],
aggregates: [
{ aggregator: "sum", width: 60, member: "sold", label: "Sold" },
{ aggregator: "sum", width: 60, member: "sold2", label: "Sold 2" }
],
colTotals: true
},
{
height: "auto",
pager: "#pager",
iconSet: "fontAwesome",
resizeStop: function () {
$(this).jqGrid("setGridWidth", this.grid.newWidth, false);
},
caption: "Daily Sales"
}
);

kendo data source group

We are trying to basically and literally group data in a data source like you can do with SQL when selecting against a table.
So I get data that looks like the following:
var grid = $("#grid").kendoGrid({
dataSource: {
data: [
{f1: "1", f2:"2", f3:"3", f4:"4", f5:"5", f6: "1"},
{f1: "1", f2:"2", f3:"3", f4:"4", f5:"5", f6: "3"},
{f1: "1", f2:"2", f3:"3", f4:"6", f5:"7", f6: "2"},
{f1: "1", f2:"2", f3:"3", f4:"6", f5:"7", f6: "1"},
{f1: "1", f2:"2", f3:"3", f4:"6", f5:"5", f6: "2"}
]},
}).data("kendoGrid");
We want to group by f1, f2, f3, f4 and sum on f6.
The result when we show this data in a grid or list view should be that the data source has only 2 rows in it
{f1: "1", f2:"2", f3:"3", f4:"4", sum: "4"},
{f1: "1", f2:"2", f3:"3", f4:"6", sum: "5"},
How can I accomplish this?

Set Reference Points for Overlaying Data onto an image in R

I have seen a few questions on here (one was even by me) with respect to using R to plot an image.
The difference here is that I need to set the reference cooridnates for my image to match the data I am looking to plot on top of the image.
More specifically, I need R to understand that the coordinates for the background image are x = (-100,100) and y = (40,-40).
I have been able to to read in the image file and plot it using the ReadImages package, but when I overlay my data using points(), the data obviously do not line up appropriately.
Any help is much appreciated.
EDIT: here are some example data and I attached the image:
structure(list(teamid = c("6", "6", "6", "6", "6", "6", "2",
"6", "6", "6", "2", "6", "10", "10", "10", "10", "20", "20",
"10", "10", "10", "20", "20", "20", "10", "10"), xcoord = c("79",
"81", "33", "34", "75", "52", "-67", "80", "44", "79", "-53",
"54", "-55", "-81", "-66", "-66", "45", "81", "-78", "-70", "-59",
"50", "53", "63", "-79", "-78"), ycoord = c("0", "0", "-18",
"-20", "6", "-11", "-7", "7", "-28", "-10", "35", "22", "25",
"-5", "25", "23", "-11", "13", "22", "16", "13", "23", "7", "16",
"8", "8")), .Names = c("teamid", "xcoord", "ycoord"), class = "data.frame", row.names = c(74328L,
74331L, 74332L, 74334L, 74336L, 74338L, 74340L, 74341L, 74346L,
74347L, 74348L, 74349L, 100136L, 100137L, 100138L, 100139L, 100147L,
100148L, 100151L, 100154L, 100156L, 100158L, 100159L, 100161L,
100163L, 100167L))
You can create an empty plot with the correct dimensions, then use the rasterImage function to plot the image, then adding the points should work fine.
Another approach is to use the updateusr function from the TeachingDemos package after plotting the image to make sure that the coordinates match what you want them to before adding lines or points.
I saved your graphic above as ice.png and ran the following code:
library(EBImage)
ice <- readImage('My Pictures/ice.png')
pos <- structure(list(teamid = c("6", "6", "6", "6", "6", "6", "2",
"6", "6", "6", "2", "6", "10", "10", "10", "10", "20", "20",
"10", "10", "10", "20", "20", "20", "10", "10"), xcoord = c("79",
"81", "33", "34", "75", "52", "-67", "80", "44", "79", "-53",
"54", "-55", "-81", "-66", "-66", "45", "81", "-78", "-70", "-59",
"50", "53", "63", "-79", "-78"), ycoord = c("0", "0", "-18",
"-20", "6", "-11", "-7", "7", "-28", "-10", "35", "22", "25",
"-5", "25", "23", "-11", "13", "22", "16", "13", "23", "7", "16",
"8", "8")), .Names = c("teamid", "xcoord", "ycoord"),
class = "data.frame", row.names = c(74328L,
74331L, 74332L, 74334L, 74336L, 74338L, 74340L, 74341L, 74346L,
74347L, 74348L, 74349L, 100136L, 100137L, 100138L, 100139L, 100147L,
100148L, 100151L, 100154L, 100156L, 100158L, 100159L, 100161L,
100163L, 100167L))
pos$xcoord <- as.numeric(pos$xcoord)
pos$ycoord <- as.numeric(pos$ycoord)
ice2 <- as.raster(ice)
pin <- par('pin')
plot( c(-100,100), c(-40,40), type='n', xlab='', ylab='',
asp=pin[1]/pin[2], axes=FALSE, xaxs='i', yaxs='i')
rasterImage(ice2, -100, -40, 100, 40, interpolate=FALSE)
with(pos, text(xcoord, ycoord, teamid, col='green', cex=1.2) )
Does this do what you want?

Resources