DataTables button displayed according to row value - datatables

I have created a JQuery DataTable from mysql row as below
with the help of PHP.
What I want is to display the button of the last Column
depending on a certain value of the $row['Status'] so I am not using JSON Data
in order to use the data object inside the DataTable variable.
Any suggestions?
<td>'.$row['Status'].'</td>
<td><button id="'.$row['ticket_id'].'" onclick="showDetails(this)" class="btn btn-default" type="submit" data-toggle="modal" data-target="#CommentModal">Edit</button></td>';

Considering you only want to show the button with id id="'.$row['ticket_id'].'"
you may just can use a simple if and concatenate echoes the result like this :
<td>'.$row['Status'].'</td>
<td>';
<?php
if($row['Status'] == 'active'){
?>
<button id="'.$row['ticket_id'].'" onclick="showDetails(this)" class="btn
btn-default" type="submit" data-toggle="modal" data-target="#CommentModal">Edit</button>
<?php
}else{
?>
<p>The status is inactive <?php echo $row['Status']; ?> </p>
<?php
}
?>
'</td>';
Considerign your $row['Status']" have the status active
Hope this suggestion helps you.

Related

Why radio buttons doesn't remain unchangeable and checked?

I'm new here and I'm writing my first php code. I want to prepare a multiple choice quiz in which, after click on a button at the end of the page, the radios button (the choices of the test) will remain checked and unchangeable. I simplify the code in this way:
<?php
$choice1 = "a";
$choice2 = "b";
?>
<form method="post" name="testForm" id="testForm">
<ul>
<li><input type="radio" name="q1" value="a"
<?php if(isset($_POST['test-result']) && $radioVal==$choice1){ echo "disabled='disabled' checked";}?>
<?php if(isset($_POST['test-result']) && $radioVal<>$choice1){ echo "disabled='disabled'";}?>>
<?php echo "<span id='question'>". $choice1 ."</span>";?> </li>
<li><input type="radio" name="q1" value="b"
<?php if(isset($_POST['test-result']) && $radioVal==$choice2){ echo "disabled='disabled' checked";}?>
<?php if(isset($_POST['test-result']) && $radioVal<>$choice2){ echo "disabled='disabled'";}?>>
<?php echo "<span id='question'>". $choice2 ."</span>";?> </li>
</ul><br>
<button class='button' name='test-result'>Finaliza el test</button>
</form>
<?php
if (isset($_POST['test-result']))
{
$radioVal = $_POST["q1"];
}
?>
However, after click on the button, all radios remain uncheged (and this is ok) but the choices made are not checked. Can someone help me? Thanks in advance!
Checkbox is not showing checked because variable $radioVal is set after input box. To resolve your issue could you please set $radioVal before from.

data-ajax-update and data-ajax-mode="replace" not working in dotnet core jquery unobtrusive ajax

I have an anchor which should replace a grid with a partial view .
<a class="btn btn-primary"
data-ajax="true"
data-ajax-method="GET"
data-ajax-mode="replace"
data-ajax-update="content"
data-ajax-url="#Url.Action("add","user")"> Create User </a>
<div class="row table-area">
<div class="col-md-12" id="content">
#Html.AjaxGrid(Url.Action("results", "user"))
</div>
</div>
I see it calls the user action with partial view but it never updates the section with id="content".
Here is my controller method -
[Route("add")]
public IActionResult AddUser()
{
return PartialView("Partials/AddUser",new RegisterViewModel());
}
Ideally it should replace the grid content with the partial view altogether but it is not replacing . The response status is 200 and I can see that the contents are being returned in response . Anybody has any idea what is the issue here ?
Change data-ajax-update="content" to data-ajax-update="#content"
Rather than using data-ajax-url, use the asp-controller and asp-action and the #content should work.
<a class="btn btn-primary" asp-controller="user" asp-action="add"
data-ajax="true"
data-ajax-method="GET"
data-ajax-mode="replace"
data-ajax-update="#content">Create User</a>

How to create dynamic field in Yii2?

I have one table where I am saving field name.
Now I want to use those fields in another model. So, How can I give name to that field?
e.g.
I have table named as Config with fields(id,key).
Data can be
1, Blog url
2, Site url
Now, I have 1 form where admin will add those value to database.
In Yii2 we create input field like
<?= $form->field($model, 'name')->textInput() ?>
But I want to create two textboxes with name blog url and site url.
So, How can I create it? What I have to write in place of name?
run this code on your command prompt
php composer.phar require --prefer-dist wbraganca/yii2-dynamicform "*"
after completion of above code.
add the following code in your form.
_form.php
<div class="panel panel-default">
<div class="panel-heading"><h4><i class="glyphicon glyphicon-envelope"></i> Addresses</h4></div>
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsAddress[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsAddress as $i => $modelAddress): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Address</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelAddress->isNewRecord) {
echo Html::activeHiddenInput($modelAddress, "[{$i}]id");
}
?>
<?= $form->field($model, "[{$i}]name")->textInput(['maxlength' => true]) ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>

Wordpress Loop with Bootstrap 3.0

Hey guys below I have a interesting problem.... I am trying to setup a left and right side post so that I can take things like read more, post date or author and have them be in the col-md-4 and have the title and the post content along with read more be inside the col-md-8
I have a feeling I am going about this pretty strange as I am rusty as hell with my php and wordpress so any help in achieving this would be helpful. Interesting problem is I have two read more's put in place with one having a display:none for WHATEVER reason if I remove that my read more's go bonkers on the page.
The code:
<?php
$myposts = get_posts('numberposts=5
&category=homeposts');
foreach($myposts as $post) :?>
<div class="col-md-8" style="background:#000;">
<h3><a href="<?php echo the_permalink($post->ID); ?>" title="<?php echo $post->post_title;?>">
<?php echo $post->post_title ?></a></h3>
<?php echo substr($post->post_content,0,500) ?>
<a class="btn btn-default" style="display:none;" role="button" href="<?php echo get_permalink(); ?>">Read More</a>
</div>
<div class="col-md-4" style="background:#000;"><a class="btn btn-default" role="button" href="<?php echo get_permalink(); ?>">Read More</a></div>
<?php endforeach; ?>
ok so what is wrong with this....
<?php
$myposts = get_posts('numberposts=5
&category=homeposts');
foreach($myposts as $post) :?>
<div class="col-md-8">
<h3><a href="<?php echo the_permalink($post->ID); ?>" title="<?php echo $post->post_title;?>">
<?php echo $post->post_title; ?></a></h3>
<?php echo $post->the_excerpt; ?>
<a class="btn btn-default" style="display:none;" role="button" href="<?php echo get_permalink(); ?>">Read More</a>
</div>
<?php endforeach; ?>

Have to Double Click to Get Data From MySQL Database Bootstrap 3 Select Library

I have an application which is getting some data from MySQL Database by using Bootstrap 3 Group Button and Bootstrap select library as:
<div class="panel panel-default">
<div class="panel-heading">4 - Select Species <button type="button" class="btn btn-default btn-xs pull-right" id="specicPop">?</button></div>
<div class="panel-body">
<div class="btn-group" id="speciesSelect">
<button id="allspecies" type="button" class="btn btn-default btn-sm">All Species</button>
<button id="aquatic" type="button" class="btn btn-default btn-sm">Aquatic</button>
<button id="terrestria" type="button" class="btn btn-default btn-sm">Terrestrial</button>
</div>
<select class="selectpicker" id="selectPicker" class="form-control" data-container="body" data-live-search="true">
<option value="0">Select From The List</option>
</div>
</div>
and the ajax is as:
$('.btn-group .btn').click(function(){
$( ".selectpicker" ).selectpicker("refresh");
$.post(
'con/animalList.php',
{ selType : this.id },
function(data)
{
$('#selectPicker').html(data);
}
);
});
the PHP part is like
if ($result->num_rows > 0)
{
$resultStr.= '<option value="0">Select From The List</option><option';
while($row = $result->fetch_assoc())
{
$resultStr.= '<option value="'.$row['id'].'">'.$row['fName'].'</option>';
}
}
else
{
$resultStr = 'Nothing found';
}
Now the problem is , I have to Double click or Click Twice to load the select element with options from database. Please be informed that PHP part is working fine and I am getting correct data but I can not figure it out why the First click is not working!
Can you please let me know how to fix this?
Thanks
Use the debugger tools of your current browser (usually visible through F12 on Windows).
Then add debugger; to your code to see when the code gets executed.
$('.btn-group .btn').click(function(){
// this will pause your execution in your browser
// and shows you the line
debugger;
});
This way, you will see if the first click is realy not triggering.
If it is not, you might have an error somewhere different in your code.
Do you have other JS code that might break your code?