Change checkbox depending on value in data global attribute - checkbox

I am trying to change/disable a checkbox based on the data-count global attribute set in the td at the right of the checkbox.
data-count = 0 -> checkbox should be disabled
data-count > 0 -> checkbox should be checked
$('td.day').each(function() {
// set checkbox disable
if ($(this).attr('data-count') == 0) {
} else {
// set checkbox checked
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<table id="mytable">
<thead>
<th> </th>
<th>Col1</th>
<th> </th>
<th>Col2</th>
</thead>
<tbody>
<tr id="rw1">
<td><input type="checkbox" name="check" /></td>
<td class="day data-count="0">10</td>
<td><input type="checkbox" name="check" /></td>
<td class="day data-count="2">11</td>
</tr>
<tr id="rw2">
<td><input type="checkbox" name="check" /></td>
<td class="day data-count="1"">20</td>
<td><input type="checkbox" name="check" /></td>
<td class="day data-count="0">21</td>
</tr>
</tbody>
</table>
</div>

You can check/uncheck checkboxes via call to .prop('checked', value)
You can query previous element via .prev
$('td.day').each(function() {
if ($(this).attr('data-count') == 0) {
// set checkbox UNCHECKED
$(this).prev().find('input').prop('checked', false);
} else {
// set checkbox CHECKED
$(this).prev().find('input').prop('checked', true);
}
});
Working example on codepen

Related

Angular Datatables using ng-repeat - how to set a column as not Sortable

I am rendering my DataTable the angular way - see sample table below.
<table id="tblSamples" datatable="ng" dt-options="mainCtrl.dtOptions" dt-instance="mainCtrl.dtInstance" class="table table-responsive table-hover">
<thead>
<tr>
<th>Number</th>
<th>Source</th>
<th>Type</th>
<th>SubCat</th>
<th>Product</th>
<th>Applied Amount</th>
<th>Sample Amount</th>
<th><input type="checkbox" ng-model="mainCtrl.selectAll" ng-click="mainCtrl.toggleAll(mainCtrl.selectAll, mainCtrl.Samples)"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="sampleItem in mainCtrl.Samples">
<td ng-if="sampleItem.TTTId != null"><a title="View {{sampleItem.TTT.Number}}" href="/TTT/Details/{{sampleItem.TTTId}}"><u>{{sampleItem.TTT.Number}}</u></a></td>
<td ng-if="sampleItem.PPPId != null"><a title="View {{sampleItem.PPP.Number}}" href="/PPP/Details/{{sampleItem.PPPId}}"><u>{{sampleItem.PPP.Number}}</u></a></td>
<td ng-if="sampleItem.MMMId != null"><a title="View {{sampleItem.MMM.Number}}" href="/MMM/Details/{{sampleItem.MMMId}}"><u> {{sampleItem.MMM.Number}}</u></a></td>
<td ng-if="sampleItem.LLLId != null"><a title="View {{sampleItem.LLL.Number}}" href="/LLL/Details/{{sampleItem.LLLId}}"><u>{{sampleItem.LLL.Number}}</u></a></td>
<td>{{sampleItem.Type.Source.Name}}</td>
<td>{{sampleItem.Type.Name}}</td>
<td ng-if="sampleItem.SubCatId != null">{{sampleItem.SubCat.Name}}</td>
<td ng-if="sampleItem.SubCatId == null"></td>
<td ng-if="sampleItem.ProductId != null">{{sampleItem.Product.Name}}</td>
<td ng-if="sampleItem.ProductId == null"></td>
<td>{{sampleItem.Amount}}</td>
<td ng-disabled="sampleItem.ForAdd != true"><input type="number" id="SampleAmount" name="SampleAmount" class="form-control ng-pristine ng-untouched ng-valid ng-not-empty" ng-model="sampleItem.SampleAmount" min="0" required /></td>
<td><input type="checkbox" ng-model="sampleItem.ForAdd" ng-click="mainCtrl.toggleOne(mainCtrl.Samples)"></td>
</tr>
</tbody>
</table>
How do I set a column as not sortable just like the code below when I define the columns in the angular controller
DTColumnBuilder
.newColumn(null)
.withTitle('Actions')
.notSortable()
.renderWith(actionsHtml)
Look at http://l-lin.github.io/angular-datatables/archives/#!/angularWayWithOptions
Instead of a columns section include a columnDefs with indexed targets:
<table id="tblSamples" datatable="ng" dt-column-defs="dtColumnDefs" ....>
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(1).notSortable()
]
Indexes are zero based, so the second column will not be sortable. I normally avoid the "builders" and just use
$scope.dtColumnDefs = [{
targets: 1,
orderable: false
}]
If you disable ordering for the first column you will still see a sorting arrow, because the default order is [[0, 'asc']]. You can prevent this in dtOptions by
.withOption('order', [])

How can I click on an HTML row then show the values of the row in input texts

How can I click on an HTML row then show the values of the row in input texts to able the user to edit them.
in controller :
$scope.data = [];
$scope.selectedMember = { Code: "", Latin: "", Local: "" }; //new property
$scope.showInEdit = function (member)
{
$scope.selectedMember = member;
}
in ng-repeat :
<table border="1" ng-hide="Hide">
<thead>
<tr>
<th>Code</th>
<th>Latin Description</th>
<th>Local Description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="c in Contracts | filter:Code | filter:Latin | filter:Local track by $index">
<td>{{c.Staff_Type_Code}}</td>
<td>{{c.L_Desc}}</td>
<td>{{c.A_Desc}}</td>
<!--<td><input type="button" value="Edit" ng-click="Edit(c)"/> </td>-->
</tr>
</tbody>
</table>
In HTML :
<table>
<tr>
<td>Code</td>
<td><input type="text" size="10" pattern="^[a-zA-Z0-9]+$" title="Alphnumeric" autofocus ng-model="selectedMember.Code.Staff_Type_Code"></td>
</tr>
<tr>
<td>Latin Description</td>
<td><input type="text" size="35" ng-model="Latin.L_Desc"></td>
</tr>
<tr>
<td>Local Description</td>
<td><input type="text" size="35" ng-model="Local.A_Desc"></td>
</tr>
Thanks lot
You just need to update your scope variables in function like
$scope.Latin.L_Desc = c.example;
After that you'll see these values in input fields.
If you want to show values in this code
<table>
<tr>
<td>Code</td>
<td><input type="text" size="10" pattern="^[a-zA-Z0-9]+$" title="Alphnumeric" autofocus ng-model="selectedMember.Code.Staff_Type_Code"></td>
</tr>
<tr>
<td>Latin Description</td>
<td><input type="text" size="35" ng-model="Latin.L_Desc"></td>
</tr>
<tr>
<td>Local Description</td>
<td><input type="text" size="35" ng-model="Local.A_Desc"></td>
</tr>
Then your object must be like this :
$scope.selectedMember = { Code: "", Latin: {A_Desc:""}, Local: {L_Desc:""} };
And in controller function
$scope.showInEdit = function (member)
{
$scope.selectedMember.Latin.L_Desc = member;
}

How to show pop up in table validation in angular JS

what should I use for displaying faculty Id is needed pop up box during validation of data inside tables. If I am not entering faculty Id then it shouldn't get added and should show that message.
<table ng-form name="myForm">
<tr>
<td>Faculty ID</td>
<td><input type="text" ng-model="faculty.id" required/></td>
</tr>
<tr>
<td>Faculty Name:</td>
<td><input type="text" ng-model="faculty.name" /></td>
</tr>
<tr>
<td>Faculty Salary:</td>
<td><input type="text" ng-model="faculty.salary" /></td>
</tr>
<tr>
<td colspan="2"><button ng-disabled="myForm.$invalid" ng-click="addfaculty(faculty)">ADD</button></td>
</tr>
</table>
you made a typo:)
ng-disbaled
should be ng-disabled
You can do this
<table ng-form name="myForm">
<tr>
<td>Faculty ID</td>
<td ><input type="text" ng-model="faculty.id" required/></td>
</tr>
<tr>
<td>Faculty Name:</td>
<td><input type="text" ng-model="faculty.name" /></td>
</tr>
<tr>
<td>Faculty Salary:</td>
<td><input type="text" ng-model="faculty.salary" /></td>
</tr>
<tr>
<td colspan="2"><button ng-disabled="myForm.$invalid" ng-click="addfaculty(faculty)">ADD</button></td>
</tr>
</table>

Why am i getting this error: Object of class stdClass could not be converted to int?

I am getting an error message which i attached a pic of, everything is working fine except the "attendance" part which is not showing in the view, i do not know what the problem is, i sure its something simple i am just not seeing it, please let me know where i am going wrong. Thank you.
error message
public function edit_data()
{
$show = $_POST['id'];
$query = $this->db->query("SELECT * FROM participants_info WHERE participant_id=$show");
$query2 = $this->db->query("SELECT * FROM participants_attendance WHERE participant_id=$show");
$query3 = $this->db->query("SELECT * FROM pcs_schedule WHERE participant_id=$show");
$data_view= $query->row();
$data_view2= $query2->row();
$data_view3= $query3->row();
trigger_error("SPECIAL".print_r($data_view, true));
trigger_error("SEVERE".print_r($data_view2, true));
trigger_error("RED".print_r($data_view3, true));
$aggregate_data_view=array('participant_id'=>'',
'First_Name'=>'','Last_Name' =>'','Function'=>'',
'Stlc_id'=>'','Address'=>'','City'=>'','State'=>'',
'Zip_Code'=>'','Phone_Number'=>'','Latitude'=>'','Longitude'=>'',
'Disenrolled'=>'','Deceased'=>'','participant_att_id'=>'','Attendance_Monday'=>'',
'Attendance_Tuesday'=>'','Attendance_Wednesday'=>'','Attendance_Thursday'=>'','Attendance_Friday'=>'',
'Lanyard_Status'=>'','Assistive_Devices'=>'','WheelChair_Van'=>'','TransitVan_240'=>'','TransitVan_360'=>'',
'Subaru_Impreza'=>'','Comments'=>'','pcs_id'=>'','Monday_Pick_Up'=>'','Monday_Drop_Off'=>'','Tuesday_Pick_Up'=>'',
'Tuesday_Drop_Off'=>'','Wednesday_Pick_Up'=>'','Wednesday_Drop_Off'=>'','Thursday_Pick_Up'=>'','Thursday_Drop_Off'=>'',
'Friday_Pick_Up'=>'','Friday_Drop_Off'=>'','Saturday_Pick_Up'=>'','Saturday_Drop_Off'=>'','Sunday_Pick_Up'=>'','Sunday_Drop_Off'=>'','Lanyard_Status'=>'','Assistive_Devices'=>'','WheelChair_Van'=>'','TransitVan_240'=>'','TransitVan_360'=>'','Subaru_Impreza'=>'','Comments'=>''
);
$aggregate_data_view['participant_id']=$data_view->participant_id;
$aggregate_data_view['First_Name']=$data_view->First_Name;
$aggregate_data_view['Last_Name']=$data_view->Last_Name;
$aggregate_data_view['Function']=$data_view->Function;
$aggregate_data_view['Stlc_id']=$data_view->Stlc_id;
$aggregate_data_view['Address']=$data_view->Address;
$aggregate_data_view['City']=$data_view->City;
$aggregate_data_view['State']=$data_view->State;
$aggregate_data_view['Zip_Code']=$data_view->Zip_Code;
$aggregate_data_view['Phone_Number']=$data_view->Phone_Number;
$aggregate_data_view['Latitude']=$data_view->Latitude;
$aggregate_data_view['Longitude']=$data_view->Longitude;
$aggregate_data_view['Disenrolled']=$data_view->Disenrolled;
$aggregate_data_view['Deceased']=$data_view->Deceased;
if($data_view2 > 0)
{
$aggregate_data_view['participant_att_id']=$data_view2->participant_att_id;
$aggregate_data_view['Attendance_Monday']=$data_view2->Attendance_Monday;
$aggregate_data_view['Attendance_Tuesday']=$data_view2->Attendance_Tuesday;
$aggregate_data_view['Attendance_Wednesday']=$data_view2->Attendance_Wednesday;
$aggregate_data_view['Attendance_Thursday']=$data_view2->Attendance_Thursday;
$aggregate_data_view['Attendance_Friday']=$data_view2->Attendance_Friday;
$aggregate_data_view['Lanyard_Status']=$data_view2->Lanyard_Status;
$aggregate_data_view['Assistive_Devices']=$data_view2->Assistive_Devices;
$aggregate_data_view['WheelChair_Van']=$data_view2->WheelChair_Van;
$aggregate_data_view['TransitVan_240']=$data_view2->TransitVan_240;
$aggregate_data_view['TransitVan_360']=$data_view2->TransitVan_360;
$aggregate_data_view['Subaru_Impreza']=$data_view2->Subaru_Impreza;
$aggregate_data_view['Comments']=$data_view2->Comments;
//$aggregate_data_view['participant_id']=$data_view2->participant_id;
}
if($data_view3 > 0)
{
$aggregate_data_view['pcs_id']=$data_view3->pcs_id;
$aggregate_data_view['Monday_Pick_Up']=$data_view3->Monday_Pick_Up;
$aggregate_data_view['Monday_Drop_Off']=$data_view3->Monday_Drop_Off;
$aggregate_data_view['Tuesday_Pick_Up']=$data_view3->Tuesday_Pick_Up;
$aggregate_data_view['Tuesday_Drop_Off']=$data_view3->Tuesday_Drop_Off;
$aggregate_data_view['Wednesday_Pick_Up']=$data_view3->Wednesday_Pick_Up;
$aggregate_data_view['Wednesday_Drop_Off']=$data_view3->Wednesday_Drop_Off;
$aggregate_data_view['Thursday_Pick_Up']=$data_view3->Thursday_Pick_Up;
$aggregate_data_view['Thursday_Drop_Off']=$data_view3->Thursday_Drop_Off;
$aggregate_data_view['Friday_Pick_Up']=$data_view3->Friday_Pick_Up;
$aggregate_data_view['Friday_Drop_Off']=$data_view3->Friday_Drop_Off;
$aggregate_data_view['Saturday_Pick_Up']=$data_view3->Saturday_Pick_Up;
$aggregate_data_view['Saturday_Drop_Off']=$data_view3->Saturday_Drop_Off;
$aggregate_data_view['Sunday_Pick_Up']=$data_view3->Sunday_Pick_Up;
$aggregate_data_view['Sunday_Drop_Off']=$data_view3->Sunday_Drop_Off;
$aggregate_data_view['Lanyard_Status']=$data_view3->Lanyard_Status;
$aggregate_data_view['Assistive_Devices']=$data_view3->Assistive_Devices;
$aggregate_data_view['WheelChair_Van']=$data_view3->WheelChair_Van;
$aggregate_data_view['TransitVan_240']=$data_view3->TransitVan_240;
$aggregate_data_view['TransitVan_360']=$data_view3->TransitVan_360;
$aggregate_data_view['Subaru_Impreza']=$data_view3->Subaru_Impreza;
$aggregate_data_view['Comments']=$data_view3->Comments;
//$aggregate_data_view['participant_id']=$data_view3->participant_id;
}
$data4view['aggregate_data_view']=$aggregate_data_view;
$this->load->helper('url');
$this->load->view('edit_data', $data4view);
}
My View: i have included part that pertains to error only.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<title>
</title>
</head>
<body ng-app="app" ng-controller="decontroller" class="container">
<div id="banner" style="text-align:center; margin-left:auto; margin-right:auto; display:block;">
<img src="http://intranet.gfhs.local/stlc_trans/STLC-Tree-Logo-PACE.png">
</div>
<h2></h2>
<h3>Personal Information:</h3>
<div id="validation-errors">
</div>
<form method="post" accept-charset="utf-8" ng-submit="processRequest()">
<table class="table table-bordered">
<tbody>
<tr>
<td>ParticipantID</td>
<td>{{edit.Stlc_id}}</td>
</tr>
<tr>
<td>First Name:<br>
</td>
<td>{{edit.First_Name}}</td>
</tr>
<tr>
<td>Last Name:<br>
</td>
<td>{{edit.Last_Name}}</td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name ="Address" ng-model="edit.Address" required></td>
</tr>
<tr>
<td>Phone:</td>
<td><input size="20" name ="phone" ng-model="edit.Phone_Number" ></td>
</tr>
<tr>
<td>Assistive Devices:</td>
<td><input name ="Assistive_Devices" ng-model="edit.Assistive_Devices" ></td>
</tr>
<tr>
<td>Lanyard Code</td>
<td>
<input name ="Lanyard_Status" ng-model="edit.Lanyard_Status" /> </td>
</tr>
<tr>
<td>Comments</td>
<td>
<textarea cols="100" name="comments" ng-model="edit.Comments">.</textarea>
</td>
</tr>
<tr>
<td>Disenrolled</td>
<td><input name="disenrolled" type="checkbox" ng-model="edit.Disenrolled" ></td>
</tr>
<tr>
<td>Deceased</td>
<td><input name="deceased" type="checkbox" ng-model="edit.Deceased" ></td>
</tr>
</tbody>
</table>
<h3>Days in Center<br></h3>
<table class="table table-bordered">
<tbody>
<tr>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
</tr>
<tr>
<td><input name="Attendance_Monday" type="checkbox" ng-model="edit.Attendance_Monday" ></td>
<td><input name="Attendance_Tuesday" type="checkbox" ng-model="edit.Attendance_Tuesday" ></td>
<td><input name="Attendance_Wednesday" type="checkbox" ng-model="edit.Attendance_Wednesday" ></td>
<td><input name="Attendance_Thursday" type="checkbox" ng-model="edit.Attendance_Thursday" ></td>
<td><input name="Attendance_Friday" type="checkbox" ng-model="edit.Attendance_Friday" ></td>
</tr>
</tbody>
</table>
error message
when you do this $data_view= $query->row();, $data_view becomes an object. you can check that by var_dump($data_view). so you can not use it like if($data_view > 0) because $data_view is not an integer. if you are checking if $data_view contains any data, you can check it like this if(count($data_view) > 0).
that should work. :)

How to select only filtered table data in angularjs?

This is My Code:
<div>
<input type="search" class="form-control" placeholder="Search Student" ng- model="stdsearch" />
</div>
<table class="table" >
<thead>
<tr>
<th><input type="checkbox" ng-model="master"></th>
<th>Admission No</th>
<th>Student Name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in ClassStudents | filter:stdsearch">
<td><input id="checkSlave" type="checkbox" ng-checked="master" ng-model="student.isselected" aria-label="Slave input"></td>
<td>{{student.Admission_no}}</td>
<td>{{student.First_Name}} {{student.MiddleName}} {{student.Last_Name}}</td>
</tr>
</tbody>
</table>
Here My Query is : I want to Check Only Filtered Rows in table When i check Master Checkbox(th).but here selected all rows of table when i remove Search text in search box. Pls Suggest me. 10Q.
Here what I have tried :
The plunker is here
I have created sample data as per HTML.
Use 'last1' as search value. You will get an idea.
$scope.ClassStudents = [{Admission_no :1,First_Name:'first1' ,MiddleName: 'middle1',Last_Name:'last1'},
{Admission_no :1,First_Name:'first2' ,MiddleName: 'middle1',Last_Name:'last1'},
{Admission_no :1,First_Name:'first3' ,MiddleName: 'middle2',Last_Name:'last2'},
{Admission_no :1,First_Name:'first4' ,MiddleName: 'middle3',Last_Name:'last1'}
];
$scope.checkUncheck = function(masterCheck){
angular.forEach( $scope.ClassStudents,function(value,key){
if(masterCheck && !$scope.stdsearch){
value.master = true;
}else{
value.master = false;
}
})
}
filter('customFilter',function(){
return function(input,masterCheck,stdsearch){
angular.forEach(input,function(value,key){
if(stdsearch){
if(masterCheck){
value.master = true;
}else{
value.master = false;
}
}
})
return input;
}
})
<body ng-controller="testCtrl">
<input type="text" ng-model="stdsearch">
<table class="table" >
<thead>
<tr>
<th><input type="checkbox" ng-model="master" ng-change = "checkUncheck(master) "></th>
<th>Admission No</th>
<th>Student Name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in ClassStudents |filter : stdsearch| customFilter : master : stdsearch">
<td><input id="checkSlave" type="checkbox" ng-checked="student.master" ng-model="student.isselected" aria-label="Slave input"></td>
<td>{{student.Admission_no}}</td>
<td>{{student.First_Name}} {{student.MiddleName}} {{student.Last_Name}}</td>
</tr>
</tbody>
</table>
</body>
Please let me know if there is any error.

Resources