Is it possible to have a vertical MVC grid? - atk4

I have a MVCgrid with few fields with and expander to view all the detials.
Inside the expander, in order to view all the details I use an MVCform without submit action, but it feels weird.
Is it possible to have a MVCgrid vertical to show one single record, so I can see all the details, I mean like this:
+-------+-------+------+
| col1 | col2 |expand|
+-------+-------+------+
| data1 | data2 |[view]|
+-------+-------+------+
+-------+-------+
| col1 | data1 |
+-------+-------+
| col2 | data2 |
+-------+-------+
| col3 | data3 |
+-------+-------+
+-------+-------+------+
| data2 | data3 |[view]|
+-------+-------+------+

Sure, here you go:
$model=$this->add('Model_Alumno')->loadData($_GET['id']);
$data=array();
foreach($model->get() as $key=>$val){
$row=array[];
$row['label']=$model->getField($key)->caption();
$row['val']=$val;
$data[]=$row;
}
$g=$this->add('Grid');
$g->addColumn('text','label');
$g->addColumn('text','val');
$g->setStaticSource($data);

Related

Multi-cell Row and Column Headers wpf

After a lot of google search, I got an example on merging Header columns and adding rows as per my requirement but it is c1flexgird code I am not able to convert in WPF main form.
https://www.grapecity.com/componentone/docs/wpf/online-flexgrid/MultipleCellRow.html
My data structure also like
col1 | col1 | col2 | col2 | col3 | col3
and I want add rows like below
col1 | Col2 | col3
A | B | A | B | A | B
Please have a look on my issue to fix my problem. Thanks

How to add a checkbox within a markdown table in Gitlab?

I am trying to set up a table in markdown that I can store in a Gitlab Wiki.
The table looks something like this:
| Col1 | Col2 | Col 3 | Col4 |
| :---: | :---: | :---: | --- |
| ID1 | Yes | No | some text |
Here is how the table looks:
Col1
Col2
Col 3
Col4
ID1
Yes
No
some text
What I would like to do instead of editing and changing the cell to be Yes or No manually, that I could use a checkbox, normally "- [ ]" should work but apparently does not work inside of table.

DB design for alternative components

I'm trying to figure out the "best way" to design a database for a product configurator, where there are Items and Components. Now each Item can have multiple Components, where (potentially) any Component can have other Component(s) which can be its valid substitute(s) or incompatible with it.
P.S. Sorry for the noob question and for my poor English.
Items and Components relationship can be done by one to many approach. You can design your tables by connecting primary keys and foreign keys to each other.
My suggestion for your other problem is that to use "parent_id" approach. A component table can have a "parent_id" column, so you can set the actual component and its substitutes.
Here is the example Components table:
+----+---------+-----------+
| id | item_id | parent_id |
+----+---------+-----------+
| 1 | 1 | null |
| 2 | 1 | 1 |
| 3 | 1 | 1 |
+----+---------+-----------+
The table above, item_id = 1 has three components with ids 1,2 and 3. The component with id=1 has two substitutes which are 2 and 3.
UPDATE
+----+---------+-----------+
| id | item_id | parent_id |
+----+---------+-----------+
| 1 | 1 | null |
| 2 | 1 | 1 |
| 3 | 1 | 2 |
+----+---------+-----------+
The table above, component_id 3 is the substitute of component_id 2 (look at its parent_id), component_id 2 is the substitute of component_id 1.
Item-Component table like this:
+--+------------+---------+-----------+
|id|component_id|parent_id|parent_type|
+--+------------+---------+-----------+
| 1| 1| 1| i|
| 2| 2| 1| c|
+--+------------+---------+-----------+
where, the value of parent_type shows the parent is item column (with i) or component column (with c)
Item table like this:
+--+-------+
|id|content|
+--+-------+
| 1| xxx|
+--+-------+
Component table like this:
+--+-------+-------------+
|id|content|other_columns|
+--+-------+-------------+
| 1| xxx| ...|
| 2| xxx| ...|
+--+-------+-------------+

Eloquent ORM Model Two or More Table

I have a problem that I couldn't deal with it. I have a News table includes TitleID, TextID, ImageID. And three more tables Titles, Texts, Images. I want to get all of them in one model. But when I try, got result like array in array . But I want it like:
[ News: [ { ID, Title, Text, Image } ] ]
Eloquent ORM responds it like:
[ News: [ { ID, Title: [ID, Title], Text: [ID, Text], Image: [ID, Image] } ] ]
Database Structure
News =>
+-----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| TitleID | int(11) | NO | | NULL | |
| TextID | int(11) | NO | | NULL | |
| ImageID | int(11) | NO | | NULL | |
| CatID | int(11) | NO | | NULL | |
| OlusturmaZamani | datetime | NO | | NULL | |
| YayinZamani | datetime | NO | | NULL | |
| DuzenlemeZamani | datetime | YES | | NULL | |
| Onay | tinyint(11) | NO | | NULL | |
| Hit | int(11) | YES | | NULL | |
+-----------------+-------------+------+-----+---------+----------------+
Titles =>
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| TitleText | text | NO | | NULL | |
+------------+---------+------+-----+---------+----------------+
the other tables like title table.
Is there a reason you've extracted Title and Text to their own table?
A solution for you would be something like what you see in this post:
Add a custom attribute to a Laravel / Eloquent model on load?
Tweaked for your example:
Assume you changed the relationShip to "titleTable", just to avoid collision
class News extends Eloquent {
protected $appends = array('title');
public function getTitleAttribute()
{
return $this->titleTable->TitleText;
}
}
Try eager loading.
If you have created relationships among News, Titles, Text and Image tables, you can load the relationship models by eager loading.
$news = News::with('title','text','image)->find(1);
Sounds like that ORM "over-normalizes". There is no reasonable reason for news attributes such as title, text, and image to be put in separate tables JOINed by an "id".
"Eager loading" sounds like a kludge to make it feel like the columns are in the News table when they aren't. This leads to unnecessary inefficiencies.

Database Views to simulate normalised tables from a single denormalised one

We have a report store with a denormalised flat table that stores identical data to a multi-table model in a different database.
Flat table (example):
| col 1 | col 2 | col 3 | timestamp |
|-------|-------|-------|-----------|
| val1 | val2 | val3 | 1/1/1990 |
| val1 | val9 | val3 | 1/1/1990 |
In multiple tables:
| id1 | id2 | timestamp |
|-----|-----|-----------|
| 001 | 111 | 1/1/1990 |
| 001 | 112 | 1/1/1990 |
| id1 | col 1 | col 3 |
|-----|-------|-------|
| 001 | val1 | val3 |
| id2 | col 2 |
|-----|-------|
| 111 | val2 |
| 112 | val9 |
There are several old reporting queries that we would like to port over to the new flat table without having to rewrite them all up front - there are many of them and they are complex.
Is there a way of writing Views that can simulate a set of relational tables from the single flat table, so that the old reporting queries work without modification?
HereI create dynamical IDs. You could also initialy make that table with fix keys, and always when adding or removing a row in the flattable do the same with the key here. Otherwise instead of Groub by use the OVER statement.
CREATE VIEW multitabkey AS
SELECT ROW_NUMBER() as key, col1, col3
FROM flattable
Group by col1, col3
WARNING: those keys are not persistent: if you delete the first row, all others get their id one smaler than before. You have dynamic IDs, but they are consistnet.
If you have a translation for your Keys you can use them as following:
CREATE VIEW multitabone AS
SELECT f.timestamp
FROM flattable as f
JOIN multitabkey as m ON m.col1 = f.col1 AND m.col3 = f.col3
Group by col1, col3
I assumed col1 , col2 are together a natural key.
As mentioned, this is a workaround, your DB is not in 3rd normalform what can cause inconsistency.

Resources