How to call multiple filters in DHTMLX Grid - dhtmlx

I would like to call multiple functions in DHTMLX Grid.
I have a table which has the following 7 columns
EX:
---------------------------------------------------------------
No. | Name | Age | Gender | Marital Status | Education | City |
---------------------------------------------------------------
I would like this grid to be filtered by multiple filter conditions.
For Ex: Filter the grid to have only the gender 'Male' whose age is below 35.
Currently my doFilter() function looks like this.
function doFilter() {
mygrid.filterBy(3,'M',true);
mygrid.filterBy(2,function(a){ return (a > 55);} );
}
But the grid is only filtered by age not by Gender column.
Please let me know how to apply multiple filter condition in DHTMLX Grid.

You need to use it as
mygrid.filterBy(3,'M');
mygrid.filterBy(2,function(a){ return (a > 55);}, true);
second filterBy call must have true as last parameter, to preserve results of previous filterBy call.

Related

Laravel groupby to get sum but only based on another columns value

I have multiple joins that I am doing to get one list. I can group by a certain value to get a sum but need to merge another column that is not being grouped by. My tables look kinda like this (simplified)
Quote Table
id|Name |Location |
---------------------------------
1|My First Quote|123 Main Street|
Quote Items table
quote_id| item_id
--------------------
1 | 1
--------------------
1 | 2
Items Table
id|Name |Quantity|Type
--------------------------------
1|Dog Food|2 |product
2|Delivery|1 |service
I need to show a final result like this in datatables
Name Location Qty Item
My First Quote | 123 Main Street | 2 | Dog Food
So basically i need to sum on item.quantity and show the product type as item. I have the group by working with a raw sum on the item grouped by item.id where item type is product but the where gets rid of the item service that i need to show on the row.
You can try this:
DB::table("Quote")
->select('Quote.Name','Quote.Location')
->(['Items.Quantity AS Qty','Items.Name AS Item'])
->join("Items","Items.item_id","=","Quote.quote_id")
->get();
You can define a relationship for quotes table
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Quote extends Model
{
public function items()
{
return $this->belongsToMany(Item::class);
}
}
after that, call a sum method with that relation for the column you want.
Quote::withSum('items','Quantity')->get();

Creating dynamic data validation

Given the following dataset in one sheet, let's say 'Product Types' (columns and headers displayed):
| A | B | C |
| :----------: | :------: | :-----: |
| Product Type | Desktops | Laptops |
| Desktops | Dell | Dell |
| Laptops | HP | Apple |
In another sheet, let's say 'Assets', I've set column A to require a match to the data validation of an item listed in column A of 'Product Types' (not including the header). What I'm trying to do is that once column A is selected in 'Assets', I'd like to create a dynamic query data validation that will then present the values of the column with the header in 'Product Types'.
As an example, in the 'Assets' sheet, if column A has "Laptops" selected, column B will use data validation for values under the "Laptops" column in 'Product Types'; then giving the only options as "Dell" or "Apple". Alternatively, if ColA is changed to "Desktops", data validation is defined to only allow "Dell" or "HP" as options.
I'm unsure if this is possible. However, data validation in Google Sheets claims to allow a range or "formula".
I don't remember where I sourced this formula from, but it can present the values I need when running the query within a cell. However, I'm unable to use the same formula within a data validation field.
=ARRAYFORMULA(IFERROR(VLOOKUP(A2, TRANSPOSE({'Product Types'!A1:M1;
REGEXREPLACE(TRIM(QUERY(IF('Product Types'!A2:M<>"", 'Product Types'!A2:M&",", )
,,999^99)), ",$", )}), 2, 0)))
The above query presents the correct comma-separated values of the column I want in 'Product Types', but I'm not sure if this can be translated into something data validation can use or if there's altogether a different method to accomplish this.
P.S. I'm new. Markdown for the table seems to work when editing, but not when published..
the answer is no. data validation does not support direct input of complex formulae. you will need to run your formula in some column and then reference the range of that column within the data validation

Laravel: How can I add an individual price from a table for each date within a given date range?

I try to calculate the room rates dynamically. My table of room rates has currently three fields:
id | room_rate | starting_from | ending_in
1 | 60 | 2019-12-01 | 2019-12-20
2 | 80 | 2019-12-21 | 2020-01-04
If the user has a check-in and check-out date, I would like to check the price for each day.
My public function to get the indivudal nights looks like this:
$booking_date_start[] = $request->input('booking_date_start');
$booking_date_end[] = $request->input('booking_date_end');
$booking_total = array();
foreach(array_combine($booking_date_start, $booking_date_end) as $check_in => $check_out) {
$check_in = new Carbon($check_in);
$check_out = new Carbon($check_out);
while ($check_in->lte($check_out)) {
$booking_total[] = $check_in->toDateString();
$check_in->addDay();
}
array_pop($booking_total);
}
return response()->json($booking_total);
Output of my function (check-in: 2019-12-20; check-out: 2019-12-23):
["2019-12-20","2019-12-21","2019-12-22"]
How can I parse the table of room rates and add the indivudal price for each date?
I need something like this:
["2019-12-20, 60","2019-12-21, 80","2019-12-22, 80"]
Thanks!
I solved this. For those who are interested in.
First I refactored my table of room rates. I use for each date a separate entry in my table with the individual price (no date ranges anymore).
Second I filtered my table of room rates. I combined the $booking_total value with my database query (whereIn method) and decode the result in a JSON format.

ag-grid modify Row Group's Header name

I'm using ag-grid to display a table which has a Row Grouping.
The column that I group by is invisible since its value holds no meaning.
So for example, I will have the following (fully collapsed) table:
---------------------------------
| H1 H2 H3 |
----------------------------------
| > groupId1 (1) |
----------------------------------
| > groupId2 (5) |
----------------------------------
As you see the grouping is done by user-unfriendly ID which is not reflected at all in the Column Definitions. I would like to change groupId1 / groupId2 to a user-friendly text that is assigned dynamically according to the content of the group rows.
I am using React.
I am using ag-Grids examples as a starting point, the following example embodies the problem I'm facing: (eg: https://plnkr.co/edit/VM59gScPD55PhX4y4JBj?p=preview)
It has row grouping
The grouping is done by a column that is invisible (country)
I would like to change the country name dynamically into a different value that's derived from the values of the inner row.
Thanks for your time. :)
You can also rename the rowGroup header of ag-grid by using this simple prop
autoGroupColumnDef
<AgGridReact
columnDefs={columnDefs}
rowData={rowData}
autoGroupColumnDef={{
headerName: 'Name'
}}
/>
A colleague helped me at the end, his solution was:
valueFormatter: ({ value, data }) => 'something ' + value
inside the colDef of my group, and the value to be displayed as the header is sent inside 'data'.
He said that cellRenderer is an overkill for a simple task like this.
You can pass additional params about group cell renderer and customize it like this -
colDef = {
// set the cell renderer to 'group'
cellRenderer:'agGroupCellRenderer',
// provide extra params to the cellRenderer
cellRendererParams: {
innerRenderer: myInnerRenderer, // provide an inner renderer
}
...
};
You should be then able to display any text based on custom logic using the myInnerRenderer implementation.
Here is an example from ag-grid docs. Check the Group Renderer C implementation

Populating Birt through columns

I have been trying to come up with a birt report to print food tag to no avail. What i want to show on the report is:
foodtag1 | foodtag2 | foodtag3
foodtag4 | foodtag5 | foodtag6
foodtag7 | foodtag8 | foodtag9
Can this be done?
the data is taken from a MySql Query "select dishes.name
from dishes
where find_in_set (dishes.id,(select orders.dishes from orders where orders.id = ))"
** Note: FoodTags 1-9 are all unique name of dishes
** Also note that foodtag 1-9 are representatives of a dish name. FoodTag1 can be "Yang Zhou Fried Rice", it can be "italian Pasta". it can be "Mee Goreng". Data is taken out from a datasource in MYSQL server
The easiest way--
Drag a grid element to your report, set it at 3 columns and 3 rows
In property editor, bind the grid to the data set
Drag a dynamic text element to the first cell in the grid
Then use JavaScript simular to this to filter to the desired text.
if (row["FoodTagColumn"]=='foodtag1'){
row["FoodTagColumn"]
}else null

Resources