In my MVC 5 Web App I use footable. In a table I have fields radio buttons for example that are built the form.
here is the code:
<thead>
<tr>
<th></th>
#foreach (var labelfreqdep in ViewBag.rbFreqDep)
{
<th style="text-align:center;" data-breakpoints="xs sm">
<label for="FrequencyID">#labelfreqdep.FrequencyDescription</label>
</th>
}
<th data-breakpoints="xs sm"></th>
</tr>
</thead>
<tbody>
<tr>
<td>First Chooses</td>
#foreach (var freqdep in ViewBag.rbFreqDep)
{
<td class="rd">
<input type="radio" name="A3_1" id="A3_1" value="#freqdep.FrequencyDescription" data-val="true" data-val-required="Please select">
</td>
}
<td class="rd">#Html.ValidationMessageFor(model => model.A3_1, "", new { #class = "text-danger" })</td>
</tr>
</tbody>
</table>
I also use validation for empty fields with data-val="true". The problem is that doesn't display the "Please select" message in mobile view. It works ok for desktop view. When I have expanded the tr with the plus icon the message appears. Can we just expand the rows on submit so the message to be displayed?
Any idea?
Edited
I used
$("#survey_form").submit(function (event) {
$('.surveytable').footable({
"expandAll": true
});
});`
It expands the rows on submit but it doesn't show the validation errors
For anyone who has the same issue, I solved it by giving an id to the button and then handle it through jquery
<script type="text/javascript">
jQuery(function($){
$('.surveytable').footable()
$("#survey_btn").click(function (event) {
$('.surveytable').footable({
"expandAll": true
});
});
});
</script>
Related
I have a SpringBoot application that uses datatables ,
here my datatable on the template
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Position</th>
<th>Actions1</th>
<th>Actions2</th>
</tr>
</thead>
<tbody>
<tbody>
<tr th:each="pic: ${pics}" >
<td class="col_name" >
<div class="box small">
<img th:src="${pic}"/>
</div>
</td>
<td class="col_actions">
<a style="color:#808080; margin-right: 10px;">
<input type="radio" name="${pic}" th:field="*{nadal}" th:value="${pic}" >Nadal<br>
</a>
</td>
<td><button>Delete</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Position</th>
<th>Actions1</th>
<th>Actions2</th>
</tr>
</tfoot>
</table>
and the javascript code on the same page:
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable({
searching: false,
paging: false
}).on("click", "button", function(){
alert('deleting row');
console.log($(this).parent());
table.row($(this).parents('tr')).remove().draw(false);
});
});
</script>
but When I click it makes a server submit of the form
try this:
<script type="text/javascript">
$(document).ready(function() {
const table = $('#example').DataTable({
searching: false,
paging: false
}).on("click", "button", function () {
alert('deleting row');
console.log($(this).parent());
table.row($(this).parents('tr')).remove().draw(false);
});
});
</script>
The easiest way to do whatever you want regardless of the scenario in all programming languages is just create a variable and an if statement. create a Boolean variable in the start and set the value to false. Whenever you want to display something or not display it, just create an if statement saying
if(<name of variable>){
display()
}else{
dontDisplay()
}
You don't have to say === true, you just need to give the variable's name since if you give the name it defaults to true, you only need to say === false for an else if statement.
This works all the time and you can also eliminate false positives, negatives or double alerts in many cases.
I had succeed on creating a table and implement datatable on my angular 5 project
html code for the table:
<table class="table table-hover mt-3" datatable [dtOptions]="dtOptionsContent" [dtTrigger]="dtTriggerContent">
<thead>
<tr>
<th scope="col">Content Type</th>
<th scope="col">User Occupation</th>
<th scope="col">Content Name</th>
<th scope="col">Carrot</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let reward of rewards" >
<td data-toggle="modal" data-target="#seeDetail" (click)="onSelect(reward)">{{getRewardType(reward.type)}}</td>
<td data-toggle="modal" data-target="#seeDetail" (click)="onSelect(reward)">{{getRoleType(reward.role)}}</td>
<td data-toggle="modal" data-target="#seeDetail" (click)="onSelect(reward)">{{reward.name}}</td>
<td data-toggle="modal" data-target="#seeDetail" (click)="onSelect(reward)">{{reward.carrot}}</td>
</tr>
</tbody>
</table>
.ts code for the datatable settings:
dtOptionsContent: DataTables.Settings = {};
dtTriggerContent: Subject<any> = new Subject();
#ViewChild(DataTableDirective)
dtElementContent: DataTableDirective;
.ts for get rewards:
getRewards(): void
{
this.adminService.getRewards().subscribe(rewards=> {
this.rewards = rewards;
this.dtTriggerContent.next();
});
}
The sorting, pagination, and searching are functional and when i add/delete a content to the table , the table is updated.
However, after updated, when i tried the sorting and pagination, the table content revert to the pre-added/deleted list.
I've tried destroy and rerender the table. This is the .ts code for adding content:
addSocial(role: number, rewardName: string, carrot: number): void
{
this.dtElementContent.dtInstance.then((dtInstance: DataTables.Api) => {
let currentCarrot = 0;
if(!isNaN(carrot))
{
//Setting for rewardTemp goes here
this.adminService.addReward(this.rewardTemp)
.subscribe(reward => {
dtInstance.destroy();
this.rewards.push(reward);
this.dtTriggerContent.next();
});
//Success Notification goes here
}
else
//Error Notification goes here
});
}
while it succeed to sorting the updated content after the list was updated, it spawn warning alert after rerender.
The alert contains "DataTables warning: table id=DataTables_Table_1 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3"
What is wrong??
Currently, I have a angularjs table that looks like this.
Here is the code;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="CheckCtrl">
<table class="table table-hover data-table sort display" style="width:100%">
<thead>
<tr>
<th class="Serial_">
Serial
</th>
<th class="Name_">
Name
</th>
<th class="ID_">
ID
</th>
<th class="On_off_">
On/off
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in check_items">
<td>{{item.SERIAL}}</td>
<td>{{item.NAME}}</td>
<td>{{item.ID}}</td>
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-click="rowSelected(item)"></td>
</tbody>
</table>
</div>
<script>
var app = angular.module('app',[]);
app.controller('CheckCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.check_items =
[
{
SERIAL:'Test Serial',
NAME:'Test Name',
ID : 10,
ON_OFF : '1'
}
];
$scope.rowSelected = function(row)
{
console.log(row);
};
}]);
</script>
I would like the text "On" to appear beside each checkbox in each row whenever it is checked. The text "Off" will appear beside each checkbox in each row whenever it is unchecked.
I am using angularjs v1.
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-click="rowSelected(item)">{{item.ON_OFF == 1 ? 'On' : 'Off'}}</td>
You can do this if you have AngularJS 1.1.5 or more
I have some html code which uses angularjs to show a table. On this table, there is a checkbox on each row.
The table looks like this;
Here is the html code.
<div ng-app ng-controller="CheckCtrl">
<table class="table table-hover data-table sort display" style="width:100%">
<thead>
<tr>
<th class="Serial_">
Serial
</th>
<th class="Name_">
Name
</th>
<th class="ID_">
ID
</th>
<th class="On_off_">
On/off
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in check_items">
<td>{{item.SERIAL}}</td>
<td>{{item.NAME}}</td>
<td>{{item.ID}}</td>
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'"></td>
</tbody>
</table>
</div>
Here is my angularjs controller code.
controller('CheckCtrl', ['$scope', '$http', 'configuration',
function ($scope, $http, $configuration) {
var url_api = $configuration.host + "cloe/webroot/cloe-cloud/app/API.json";
$http.get(url_api).success(function(data)
{
$scope.check_items = data;
});
This is what I want. When a user clicks on a checkbox, information regarding all the items on that particular row belonging to the clicked checkbox is sent to a angualrjs controller function for processing. This information should include the Serial, Name, ID and new state of On/Off after clicking on the checkbox.
I am using angularjs v1 and twitter bootstrap.
EDIT: Edited the original question details to indicate that the row information should be sent whenever the checkbox is clicked and not only when the checkbox is enabled.
We can use ng-change to send row data to controller as object.
After that, you can retrieve row data as following:
var serial = row.SERIAL;
var name = row.NAME;
var id = row.ID;
var onOff = row.ON_OFF;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="CheckCtrl">
<table class="table table-hover data-table sort display" style="width:100%">
<thead>
<tr>
<th class="Serial_">
Serial
</th>
<th class="Name_">
Name
</th>
<th class="ID_">
ID
</th>
<th class="On_off_">
On/off
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in check_items">
<td>{{item.SERIAL}}</td>
<td>{{item.NAME}}</td>
<td>{{item.ID}}</td>
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-click="rowSelected(item)"></td>
</tbody>
</table>
</div>
<script>
var app = angular.module('app',[]);
app.controller('CheckCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.check_items =
[
{
SERIAL:'Test Serial',
NAME:'Test Name',
ID : 10,
ON_OFF : '1'
}
];
$scope.rowSelected = function(row)
{
console.log(row);
};
}]);
</script>
You can maybe use something like this,
HTML:
<input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-change="checkSubmit(item.serial,item.name,item.id,item.on_off)">
JS:
function checkSubmit(serial,name,id,on_off){
...
/*Processing can happen now with the parameters obtained*/
...}
NOTE: The case of the variables may be wrong
Some modification to the answer provided by Natiq.
Modify this line
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-model="item.selected" ng-change="rowSelected(item)"></td>
to
<td> <input type="checkbox" ng-checked="item.ON_OFF == '1'" ng-model="item.selected" ng-click="rowSelected(item)"></td>
The modification is from ng-change to ng-click. This will solve your problem where the first click does not work but only subsequent clicks work based on the comments posted. Using ng-click ensures that every click will be detected.
I am using this (https://github.com/Eonasdan/bootstrap-datetimepicker) Date and time picker for my website, and when you open the datetime picker in a table-responsive class it does not show the date picker on top the table unless in the css you add .table-responsive { overflow:visible !important } in the css. Its all well and good doing this, but then when you shrink the screen or use it on a mobile / tablet, the table is no longer responsive and hangs off the side of the screen.
Please see this (https://jsfiddle.net/daza110/6abxn644/3/) fiddle which shows it opening correctly until you shrink the screen.
And please see this (https://jsfiddle.net/daza110/6abxn644/4/) fiddle which shrinks the table correctly, but does not show the calendar properly.
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed table-hover table-striped text-center bgwhite" id="accountTable">
<thead>
<tr>
<th class="col-sm-2">Debt Ref</th>
<th class="col-sm-2">Due Date</th>
<th class="col-sm-2">Amount Paid</th>
<th class="col-sm-2">Account</th>
<th class="col-sm-2">Reconcile Date</th>
</tr>
</thead>
<tbody>
<tr class="armitage">
<td>
<div>NOR087-DAN052</div>
</td>
<td>
<div>05/01/2016</div>
</td>
<td>
<div>180.00</div>
</td>
<td>
<div class="col-sm-12">Paralegal (951)</div>
</td>
<td>
<div class="col-sm-12">
<input type="text" placeholder="Reconcile Date" name="dates[ifbZ6A4b6r568bad40cd473]" id="dates-ifbZ6A4b6r568bad40cd473" class="form-control ">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
Jquery
jQuery('#dates-ifbZ6A4b6r568bad40cd473').datetimepicker({
format: "DD/MM/YYYY"
});
UPDATE
I hacked this but it isnt nice, I added a PHP function that attaches a DatePicker and then did the following jquery code, this removes the table-responsive and adds a temp class on show then on hide removes temp class and adds the table-responsive again:
function attachDatePick($fieldId)
{
?>
<script type="text/javascript">
jQuery(function()
{
jQuery('#<?echo $fieldId;?>').datetimepicker().on('dp.show',function()
{
jQuery(this).closest('.table-responsive').removeClass('table-responsive').addClass('temp');
}).on('dp.hide',function()
{
jQuery(this).closest('.temp').addClass('table-responsive').removeClass('temp')
});
});
</script>
<?
}
I don't understand too much what you need but is maybe this?
.table-responsive {
overflow-x: inherit;
}
See in this fiddle
easy way is setting position: static for datepicker wrapper. For instance
<td>
<div class="col-sm-12">
<input type="text" placeholder="Reconcile Date" name="dates[ifbZ6A4b6r568bad40cd473]" id="dates-ifbZ6A4b6r568bad40cd473" class="form-control ">
</div>
</td>
you can set .col-sm-12 {position: static}
I haven't found any answer about this question that really pleases.
So I adapted a another code for bootstrap dropdown with same problem inside .table-responsive
below is the main code, that I put on window:
window.setDatapickerEvents = ($parentElement) => {
$($parentElement).on('dp.show', function (e) {
const $e = $(e.target);
const $input = $e.find('input').first();
const $btn = $e.find('span.input-group-addon').first();
const $dropdownMenu = $e.find('.dropdown-menu');
const eOffset = $e.offset();
const btnWidth = $btn.outerWidth();
const inputWidth = $input.outerWidth();
const dropdownWidth = $dropdownMenu.outerWidth();
const dropdownHeight = $dropdownMenu.outerHeight();
$('body').append($dropdownMenu.detach());
$dropdownMenu.css({
'top': eOffset.top - dropdownHeight,
'left': eOffset.left + inputWidth + (btnWidth / 2) - dropdownWidth + 20,
'width': dropdownWidth,
'height': dropdownHeight,
});
});
$($parentElement).on('dp.hide', function (e) {
const $e = $(e.target);
const $dropdownMenu = $e.find('.dropdown-menu');
$e.append($dropdownMenu.detach());
$dropdownMenu.hide();
});
}
And to enable it inside scripts tag in your page
setDatapickerEvents('.table-responsive');
Before - Problem
After - Resolved
I hope it helps anyone