In drupal 7 it was no problem to make sticky header.
But in D8 - something is wrong.
My code:
$out = array();
$rows = array();
for($i = 0; $i < 700; $i++) {
$rows[$i]['ID'] = ['data' => $i];
$rows[$i]['name'] = "user_" . $i;
$rows[$i]['some'] = rand(0,634);
}
$out['table'] = [
'#theme' => 'table',
'#rows' => $rows,
'#header' => ['ID', 'Name', 'Rand'],
'#sticky' => true,
'#caption' => 'Table caption',
];
return $out;
In drupal 7:
$out['table'] = [
'#theme' => 'table',
'#rows' => $rows,
'#header' => ['ID', 'Name', 'Rand'],
'#sticky' => true,
'#caption' => 'Table caption',
];
In drupal 8:
$out['table'] = [
'#type' => 'table',
'#rows' => $rows,
'#header' => ['ID', 'Name', 'Rand'],
'#sticky' => true,
'#caption' => 'Table caption',
];
Use #type in drupal 8
In Drupal Twig Template Documentation they are providing Sticky option. You can check with that.
For Sticky header you can check with this.
Twig Template provide following options for table.
/**
* #file
* Default theme implementation to display a table.
*
* Available variables:
* - attributes: HTML attributes to apply to the <table> tag.
* - caption: A localized string for the <caption> tag.
* - colgroups: Column groups. Each group contains the following properties:
* - attributes: HTML attributes to apply to the <col> tag.
* Note: Drupal currently supports only one table header row, see
* https://www.drupal.org/node/893530 and
* http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table/7#comment-5109.
* - header: Table header cells. Each cell contains the following properties:
* - tag: The HTML tag name to use; either 'th' or 'td'.
* - attributes: HTML attributes to apply to the tag.
* - content: A localized string for the title of the column.
* - field: Field name (required for column sorting).
* - sort: Default sort order for this column ("asc" or "desc").
* - sticky: A flag indicating whether to use a "sticky" table header.
* - rows: Table rows. Each row contains the following properties:
* - attributes: HTML attributes to apply to the <tr> tag.
* - data: Table cells.
* - no_striping: A flag indicating that the row should receive no
* 'even / odd' styling. Defaults to FALSE.
* - cells: Table cells of the row. Each cell contains the following keys:
* - tag: The HTML tag name to use; either 'th' or 'td'.
* - attributes: Any HTML attributes, such as "colspan", to apply to the
* table cell.
* - content: The string to display in the table cell.
* - active_table_sort: A boolean indicating whether the cell is the active
table sort.
* - footer: Table footer rows, in the same format as the rows variable.
* - empty: The message to display in an extra row if table does not have
* any rows.
* - no_striping: A boolean indicating that the row should receive no striping.
* - header_columns: The number of columns in the header.
*
* #see template_preprocess_table()
*
* #ingroup themeable
*/
Related
I had a model with a field like
from django_mysql.models import EnumField
AGE_RANGE = ['10-20', '21-30', '31-40', '41-50', '51-60', '61-70', '71-80', '80+']
ageRange = EnumField(db_column='age_range', choices=AGE_RANGE, null=True)
I just change the enum with a space inside each item
AGE_RANGE = ['10 - 20', '21 - 30', '31 - 40', '41 - 50', '51 - 60', '61 - 70', '71 - 80', '80+']
When I was trying to do the migration, I am getting the following error,
"Data truncated for column 'age_range'
What is the solution. Thanks
I have a field named 'starting_price' in my table where I store money. I store money as an integer in cents and when i store it I multiply it with 100 so it can be stored in cents. For example, 10$ is stored as 1000 in database but when rendering it I divide it with 100 and also use number_format in twig. Now I want to add update functionality and I want to divide it with 100 before rendering it but it doesn't work. I have this in my form:
->add('starting_price', NumberType::class,[
'label' => 'Starting price',
])
and this in my twig:
{{ form_row(form.starting_price) }}
When I add /100 in my twig file it returns an error
An exception has been thrown during the rendering of a template ("Warning: A non-numeric value encountered").
This shows 12000 cents and I want it to show 120
You can use a Form Data Transformer: Doc here
$builder
->get(
'starting_price',
NumberType::class,
[
'label' => 'Starting price',
]
)
->addModelTransformer(new CallbackTransformer(
function ($data) {
return $data / 100;
},
function ($data) {
return $data * 100;
}
)
);
I am using Oracle APEX 21.1. I have a table visits with a column visit_type. visit_type has only values 1 or 2. There are 2 dialog pages(1 and 2). I need to create a query that returns a link that opens page 1 when visit_type = 1 and opens page 2 when visit_type = 2. Should I select a string with <a href=""</a> tag or use APEX_PAGE.GET_URL API. Either way, kindly, give me an example.
Here is a typical format
apex_string.format(
'<a class="t-Button t-Button--hot t-Button--simple t-Button--stretch" href="%s">%s</a>'
, apex_page.get_url
(p_application => 'YOUR_APP'
,p_page => t.visit_type
,p_items => 'p'||t.visit_type||'_id'
,p_values => t.visit_id
)
, 'Link text'
) as link_target
Don't forget to not escape special characters in your column definition.
I have a model that consists of several fields ie (Name, Description) and a properties column which is a serialized hash of custom attributes.
I am trying to write an import script to handle importing a CSV/XLS file into the database for this model and am struggling with capturing all of the unknown database fields and serializing them with their header into the properties column as a hash.
ie with the following table.
Name | Description | Field1 | Field2
Row1 | This is | Row1F1 | Row1F2
Row2 | This is | Row2F1 | Row2F2
I would like it to import into the database as
Testmodel.create(:name => Row1, :description => "This is", :properties => { :field1 => "Row1F1", :field2 => "Row1F2" })
My current SIMPLE import that I use for my other simple tables is the following. I am using Roo
def self.import(file)
spreadsheet = open_spreadsheet(file)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
chemuse = find_by_id(row["id"]) || new
chemuse.attributes = row.to_hash
chemuse.save!
end
end
My goal is for the import to catch unknown column names and then I will put them into a hash and add them to the :properties column.
So I found the following code that works but it doesn't seem very efficient but wanted to post it as an answer.
def self.import(file)
spreadsheet = open_spreadsheet(file)
cn = column_names
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
rawrow = Hash[[header, spreadsheet.row(i)].transpose]
cleansedrow = {:properties => {}}
rawrow.each do |key, value|
if cn.include?(key)
cleansedrow[key] = value
else
cleansedrow[:properties][key] = value
end
end
record = find_by_id(cleansedrow["id"]) || new
record.attributes = cleansedrow.to_hash
record.save!
end
end
I have searched for hours but could not find an answer to this, or a module to help.
We are building a store and our client needs the ability to navigate the store by manufacturer. Is there any way that the manufacturer page can list the categories and subcategories.
There seems two ways to do it.
Add brands while adding categories in admin section.
Get all categories inside the brands by join operation while viewing the manufacturer.
Are there any modules available to link up categories with manufacturers so that I can display categories inside the manufacturer page.
Or the only way is to query all the products inside the manufacturer and get the categories out of it... I guess it is not a good solution.
So any suggestions would be a great help.
Thanks.
I figured a way to find the categories that belongs to a manufacturer. The second options seems better.
Here is the function that I added to catalog/model/catalog/manufacturer.php
public function getManufacturerCategories($manufacturer_id) {
$query = $this->db->query("
SELECT
DISTINCT c.category_id,cd.name
FROM
". DB_PREFIX . "manufacturer m
LEFT JOIN ". DB_PREFIX. "product p ON (m.manufacturer_id = p.manufacturer_id)
LEFT JOIN ". DB_PREFIX. "product_to_category p2c ON (p2c.product_id = p.product_id)
LEFT JOIN ". DB_PREFIX. "category c ON (c.category_id = p2c.category_id)
LEFT JOIN ". DB_PREFIX. "category_description cd ON (cd.category_id = p2c.category_id)
WHERE
p.status = 1
AND m.manufacturer_id = '".(int)$manufacturer_id."'
AND c.status= 1
");
return $query->rows;
}
Here is the output array
stdClass Object (
[row] => Array
(
[category_id] => 20
[name] => Desktops
)
[rows] => Array
(
[0] => Array
(
[category_id] => 20
[name] => Desktops
)
[1] => Array
(
[category_id] => 24
[name] => Phones & PDAs
)
)
[num_rows] => 2 )