I am looking for some basic JavaScript help with an IF statement. I am using Yii2 Advanced template.
The code below, says IF window is less than 1024, use the following table details for the arrays. There are two arrays at the bottom in 'items'. However, I want to use different table details for each array.
So, I want to say ‘IF’ window is less than 1024 && it is array 1, use this code. 'Else', if it is array 2, use this other code.
I can’t figure out how to reference the different arrays. Any help appreciated.
Current Code:
<?php
/*Add Headers for responsive*/
$this->registerJs('$("document").ready(function () {
var alterRTabelHeaders = function () {
var resultCount = "' . $resultCount . '";
var ww = document.body.clientWidth;
if (resultCount > 0) {
if (ww < 1024) {
$("table.fold-table td:nth-of-type(1)").attr("data-before", "#");
$("table.fold-table td:nth-of-type(2)").attr("data-before", "Action");
$("table.fold-table td:nth-of-type(3)").attr("data-before", "Fields Changed");
$("table.fold-table td:nth-of-type(4)").attr("data-before", "Action Date");
$("table.fold-table td:nth-of-type(5)").attr("data-before", "By");
}
}
};
$(window).resize(function () {
alterRTabelHeaders();
});
alterRTabelHeaders();
});');
echo Tabs::widget([
'items' => [
array(
'label' => 'Quotes (' . count($model->quotes) . ')',
'content' => $this->render('quotes', ['dataProvider' => $dataProvider]),
),
array(
'label' => 'Changelog (' . count($model->feeds) . ')',
'content' => $this->render('feeds', ['feedDataProvider' => $feedDataProvider, 'feedSearch' => $feedSearch]),
)
],
'options' => array(
'class' => 'tabbable tabs-left ui-tabs-vertical ui-helper-clearfix ui-tabs-vertical'
)
]);
?>
I'm thinking of something like this below but I don't know how to write it the new IF statement correctly.
I need to say: IF it is the first array, use this code, ELSE, use the other code.
I need to know what text to put instead of this text: ** if the first array in the 'items=>array', use this **
<?php
/*Add Headers for responsive*/
$this->registerJs('$("document").ready(function () {
var alterRTabelHeaders = function () {
var resultCount = "' . $resultCount . '";
var ww = document.body.clientWidth;
if (resultCount > 0) {
if (ww < 1024) {
if (** if the first array in the 'items=>array', use this **) {
$("table.fold-table td:nth-of-type(1)").attr("data-before", "#");
$("table.fold-table td:nth-of-type(2)").attr("data-before", "Action");
$("table.fold-table td:nth-of-type(3)").attr("data-before", "Fields Changed");
$("table.fold-table td:nth-of-type(4)").attr("data-before", "Action Date");
$("table.fold-table td:nth-of-type(5)").attr("data-before", "By");
}
else {
$("table.fold-table td:nth-of-type(1)").attr("data-before", "New Heading 1");
$("table.fold-table td:nth-of-type(2)").attr("data-before", "New Heading 2");
$("table.fold-table td:nth-of-type(3)").attr("data-before", "New Heading 3");
$("table.fold-table td:nth-of-type(4)").attr("data-before", "New Heading 4");
$("table.fold-table td:nth-of-type(5)").attr("data-before", "New Heading 5");
}
}
}
};
$(window).resize(function () {
alterRTabelHeaders();
});
alterRTabelHeaders();
});');
echo Tabs::widget([
'items' => [
array(
'label' => 'Quotes (' . count($model->quotes) . ')',
'content' => $this->render('quotes', ['dataProvider' => $dataProvider]),
),
array(
'label' => 'Changelog (' . count($model->feeds) . ')',
'content' => $this->render('feeds', ['feedDataProvider' => $feedDataProvider, 'feedSearch' => $feedSearch]),
)
],
'options' => array(
'class' => 'tabbable tabs-left ui-tabs-vertical ui-helper-clearfix ui-tabs-vertical'
)
]);
?>