Struggling with Table cell Widths and inline Inputs - width

I am using bootstrap 3.3.7. I have created table using the following class
<table id="record-set" class="table table-striped table-bordered">
<thead>
<tr>
<th>Category Type</th>
<th>Station</th>
<th>MoD ID</th>
<th>Nomenclature</th>
<th>Cost</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</table>
The <tbody></tbody> with <tr><td></td></tr> is being generated from ajax call and that is working fine. However, the width of each cell changes with the length of the contents. I am unable to achieve fixed width as per the intended length of contents.
Also, How do we take inputs directly into a blank row at the end table having text, dropdown and datetimepicker.
That part of code is as follows. In this I am not able to capture the datetimepicker value also:-
$tableRow = '<div class="table-responsive"> < table class = "table table-bordered" >
< thead >
< tr >
< th > Cost < /th> < th > AE Amt < /th> < th > Status < /th> < th > Since < /th> < th > Remarks < /th> < th > Updated By < /th> < th > Updated On < /th> < /tr> < /thead> < tbody > ';
$conn = new mysqli($DBSERVER, $DBUSER, $DBPASS, $DBNAME);
$result = mysqli_query($conn, $sql);
$numberOfRecords = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result)) {
$tableRow = $tableRow.
'<tr class="info">';
$tableRow = $tableRow.
'<td>'.$row['Cost'].
'</td>';
$tableRow = $tableRow.
'<td>'.$row['AE_Amt'].
'</td>';
$tableRow = $tableRow.
'<td>'.$row['Status_Type'].
'</td>';
$tableRow = $tableRow.
'<td>'.$row['Status_Date'].
'</td>';
$tableRow = $tableRow.
'<td>'.$row['Remarks'].
'</td>';
$tableRow = $tableRow.
'<td>'.$row['UpdatedBy'].
'</td>';
$tableRow = $tableRow.
'<td>'.$row['UpdatedOn'].
'</td>';
$tableRow = $tableRow.
'</tr>';
}
$tableRow = $tableRow.
'<tr class="danger">';
//var_dump($numberOfRecords);
if ($numberOfRecords == 0) {
$WhereCondition = 'WHERE (`amwplist`.`Work_ID_by_MoD` = '.$tcn.
')';
$sql = "SELECT * FROM `amwplist` ".$WhereCondition;
$result = mysqli_query($conn, $sql);
//var_dump($sql);
} else {
mysqli_data_seek($result, $numberOfRecords - 1);
}
$row = mysqli_fetch_array($result);
$tableRow = $tableRow.
'<td>'.$row['Cost'].
'</td>';
$tableRow = $tableRow.
'<td><input id="taeamt" width="48" autofocus value="'.$row['AE_Amt'].
'"></td>';
if (IsNullOrEmptyString($row['Status_Type'])) {
$SelectedStatus = 'BOO in Progress';
} else {
$SelectedStatus = $row['Status_Type'];
}
$tableRow = $tableRow.
'<td id="tstatus" contenteditable>'.fill_Full_StatusList($conn, $SelectedStatus).
'</td>';
$tableRow = $tableRow.
'<td><input id="tsince">';
$tableRow = $tableRow.
'<td><input id="tremarks"contenteditable></td>';
$tableRow = $tableRow.
'<td id="tupdatedby">'.$userRow['userName'].
'</td>';
$datenow = new DateTime('now');
$datenow = $datenow - > format('d-m-Y H:i:s');
$tableRow = $tableRow.
'<td id="tupdatedon">'.$datenow.
'</td>';
$tableRow = $tableRow.
'</tr>';
$tableRow = $tableRow.
'</tbody>';
$tableRow. = "</table></div>";
echo($tableRow);

table tbody tr td{
width:150px !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<table id="record-set" class="table table-striped table-bordered">
<thead>
<tr>
<th>Category Type</th>
<th>Station</th>
<th>MoD ID</th>
<th>Nomenclature</th>
<th>Cost</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Category Type</td>
<td>Station</td>
<td>MoD ID</td>
<td>Nomenclature</td>
<td>Cost</td>
<td>Status</td>
</tr>
<tr>
<td>Category Type</td>
<td>Station</td>
<td>MoD ID</td>
<td>Nomenclature</td>
<td>Cost</td>
<td>Status</td>
</tr>
</tbody>
</table>

Related

ASP.NET Core MVC - How to display data from Excel into HTML table before inserting into the DB

In ASP.NET Core-6 MVC, I have excel file (student.xlsx) with this code:
Model:
public class Students
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int AdmissionYear { get; set; }
public string RegistrationNo { get; set; }
}
Controller:
public async Task<IActionResult> Upload(IFormFile file)
{
if (file == null)
{
return RedirectToAction(nameof(Index));
}
List<Students> studentList = new List<Student>();
using(var memoryStream = new MemoryStream())
{
await file.CopyToAsync(memoryStream).ConfigureAwait(false);
using(var package = new ExcelPackage(memoryStream))
{
var worksheet = package.Workbook.Worksheets[0];
if (worksheet.Dimension.Rows > 0 && worksheet.Dimension.Columns > 0)
{
for (int row = 2; row <= worksheet.Dimension.Rows; row++) // start at row 2 to skip header
{
Students student = new Students();
student.FirstName = worksheet.Cells[row, 1].Value.ToString();
student.LastName = worksheet.Cells[row, 2].Value.ToString();
student.AdmissionYear = int.Parse(worksheet.Cells[row, 3].Value.ToString());
student.RegistrationNo = worksheet.Cells[row, 4].Value.ToString();
studentList.Add(student);
}
}
}
}
return View("Index", studentList);
}
View:
<div class="form-group">
<label name-for="file">Excel xlsx Upload</label>
<input type="file" name="file" />
</div>
<input type="button" name="display" value="Show Data" id="btnShow" class="btn btn-primary" />
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th class="table-head">
<input type="checkbox" onchange="checkAll(this)" name="chk[]" />
</th>
<th>First Name</th>
<th>Last Name</th>
<th>AdmissionYear</th>
<th>RegistrationNo</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="middle" align="center" style="width: 2%;">
<input type="checkbox" onchange="checkSingle(this)" name="chk[]" />
</td>
<td></td>
<td></td>
<td> </td>
<td></td>
</tr>
</tbody>
</table>
As soon as the user choose the excel file to be uploaded, when he clicks on choose file, and clicks on Show Data, it should display the excel data in the table in html without even the submit upload button
I want to first display the imported data into HTML table in the view page before the user then submits and insert into the DB.
How do I achieve this?
Thanks
You can use JavaScript to monitor the status of the file, then read the file and load it through xlsx.full.
You can refer to my test code below:
<div class="container">
<h2 class="text-center mt-4 mb-4">Convert Excel to HTML Table using JavaScript</h2>
<div class="card">
<div class="card-header"><b>Select Excel File</b></div>
<div class="card-body">
<input type="file" name="file" id="excel_file" />
<input type="button" name="display" value="Show Data" id="btnShow" onclick="ShowData()" class="btn btn-primary" />
</div>
</div>
<div id="excel_data" class="mt-5"></div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonyous" />
<script type="text/javascript" src="https://unpkg.com/xlsx#0.15.1/dist/xlsx.full.min.js"></script>
<script>
var table_output = "";
var excel_file = document.getElementById("excel_file");
excel_file.addEventListener("change",(event) =>{
var reader = new FileReader();
reader.readAsArrayBuffer(event.target.files[0]);
reader.onload = function(event){
var data = new Uint8Array(reader.result);
var work_book = XLSX.read(data,{type:'array'});
var sheet_name = work_book.SheetNames;
var sheet_data = XLSX.utils.sheet_to_json(work_book.Sheets[sheet_name[0]],{hearder:1});
if(sheet_data.length > 0)
{
table_output += '<table class="table table-striped table-bordered">';
table_output += '<thead><tr><th>First Name </th><th> Last Name </th><th> AdmissionYear </th><th> RegistrationNo </th></tr></thead>';
table_output += '<tbody>';
for(var row = 0; row < sheet_data.length; row++)
{
table_output += '<tr>';
table_output += '<td>' + sheet_data[row].FirstName + '</td>';
table_output += '<td>' + sheet_data[row].LastName + '</td>';
table_output += '<td>' + sheet_data[row].AdmissionYear + '</td>';
table_output += '<td>' + sheet_data[row].RegistrationNo + '</td>';
table_output += '</tr>';
}
table_output += '</tbody></table>';
}
}
})
function ShowData()
{
document.getElementById("excel_data").innerHTML = table_output;
}
</script>
Test Result:
When file is selected and ShowData is clicked:
Hope this can help you.
You can import the Sheetjs library which can read your excel file and render it to a table. Demo
The library can read your data into Json, you can modify that Json to add an empty column and then hook into the render event to render the checkbox.

How do I wrap an empty submenu?

I have this menu in TYPO3:
HEADER = HMENU
HEADER {
1 = TMENU
1 {
expAll = 1
NO = 1
NO {
wrapItemAndSub = <ul class="select one"><li>|</li></ul> || <ul class="select two"><li>|</li></ul>
}
ACT < .NO
ACT = 1
ACT {
wrapItemAndSub = <ul class="current one"><li>|</li></ul> || <ul class="current two"><li>|</li></ul>
}
}
2 < .1
2.wrap = <ul class="sub">|</ul>
2.NO.wrapItemAndSub = <li>|</li>
2.ACT.wrapItemAndSub = <li class="current_sub">|</li>
}
Here is the resulting HTML code:
<ul class="current one">
<li>
Homepage
<ul class="sub">
<li>Subpage</li>
</ul>
</li>
</ul>
<ul class="current two">
<li>
Second page
</li>
</ul>
As you can see, there are no subpages below the second page. That is the reason <ul class="sub">...</ul> is not rendered for second page.
However, I need the <ul class="sub"></ul> - even if there is nothing in it.
How can I get it into my code?
Premise: the whole menu seems a bit...odd... at least for my tastes (each first level item is wrapped with an <ul>, and you also require an additional empty <ul> even without subitems...)
Said that, this trick should work: Basically I appended at the NO state a "fake" empty <ul class="sub"></ul> and I removed it when the actual subpages kick in.
HEADER = HMENU
HEADER{
1 = TMENU
1 {
expAll = 1
NO = 1
NO {
wrapItemAndSub = <ul class="select one"><li>|</li></ul> || <ul class="select two"><li>|</li></ul>
}
NO.after = <ul class="sub"></ul>
ACT < .NO
ACT = 1
ACT {
wrapItemAndSub = <ul class="current one"><li>|</li></ul> || <ul class="current two"><li>|</li></ul>
}
IFSUB < .NO
IFSUB = 1
IFSUB.after =
ACTIFSUB < .ACT
ACTIFSUB = 1
ACTIFSUB.after =
}
2 < .1
2.wrap = <ul class="sub">|</ul>
2.NO.wrapItemAndSub = <li>|</li>
2.ACT.wrapItemAndSub = <li class="current_sub">|</li>
}
This is the solution I ended up using. I still took care to remove the additional code again for the second level and I made sure the right classes still are applied on level 2:
HEADER = HMENU
HEADER {
1 = TMENU
1 {
expAll = 1
NO = 1
NO {
wrapItemAndSub = <ul class="select one"><li>|</li></ul> || <ul class="select two"><li>|</li></ul>
}
NO.after = <ul class="sub"><li class="empty"> </li></ul>
ACT < .NO
ACT = 1
ACT {
wrapItemAndSub = <ul class="current one"><li>|</li></ul> || <ul class="current two"><li>|</li></ul>
}
IFSUB < .NO
IFSUB = 1
IFSUB.after =
ACTIFSUB < .ACT
ACTIFSUB = 1
ACTIFSUB.after =
}
2 < .1
2.wrap = <ul class="sub">|</ul>
2.NO.wrapItemAndSub = <li>|</li>
2.NO.after =
2.ACT.wrapItemAndSub = <li class="current_sub">|</li>
2.ACT.after =
2.IFSUB.wrapItemAndSub = <li>|</li>
2.ACTIFSUB.wrapItemAndSub = <li class="current_sub">|</li>
}

NodeJS template literal with async map

I'm trying to generate an HTML content using template literal because I need to loop through an array. It is not returning the map content to the template literal.
const htmlData = `
<html>
... // Some content here
<table class="table table-bordered" style="width: 800px;" align="center">
<thead class="thead-light">
<tr>
<th>Company</th>
<th>Bill Date</th>
<th>Billing Days</th>
<th>Total Units</th>
</tr>
</thead>
<tbody>
${customers.map( async (customer) => {
let units = 0;
const companyDate = new Date(customer.CompanyStartDate);
const billDate = new Date(today.getFullYear(), today.getMonth(), companyDate.getDate());
const numDays = (today.getTime() - billDate.getTime()) / (1000 * 3600 * 24);
const pData = await property.getPropTotalUnitsByCompany(customer.CompanyID);
return (
`
<tr>
<td>
${pData.map(async (propData) => {
units += propData.TotalUnits;
return (
`
<div class="row">
<div class="col-sm-12" align="right">
Property: ${propData.PropertyName} Total Units: ${propData.TotalUnits}
</div>
</div>
`
);
})}
</td>
<td>${myFunctions.formatDisplayDate(billDate)}</td>
<td>${numDays}</td>
<td>${units}</td>
</tr>
`
);
})}
</tbody>
</table>
... // More content here
</html>
`;
It returns [object Promise] inside my . Here is where I have the .map(). Can't I use map in template literals?
Thank you

angular ngIf condition inside ngFor for to display like button

I'm working with angular buttons, To implement like button depends on ngif condition inside ngFor loop and i am getting the data from two MYSQL tables posts(post_id, user_id, description), likes(like_id, user_id, post_id, like_status). I joined the two table based on user_id,and i just ngIf implement the conditions depends on user_id & post_id & like_status.
I wrote these three conditions to show the button
*ngIf="( (postLikes.length != 0) && (post.user_id == like.user_id) && (post.post_id == like.post_id) && (like.like_status == 'like'))"
*ngIf="( (postLikes.length != 0) && (post.user_id == like.user_id) && (post.post_id == like.post_id) && (like.like_status == 'unlike'))"
*ngIf="( (postLikes.length == 0) && (post.user_id != like.user_id) && (post.post_id != like.post_id) && (like.like_status != 'unlike'))"
But first two conditions working fine but the last one not working if the user_id and post_id not present in a same row , so any one please correct the ngIf condition and help me.
<div class="container" style="width: 100%; height: 100%; ">
<div class="row" style=" margin: 1px; background-color: #fff; border: 2px solid #ada5a5; border-radius: 4px; ">
<!-- ngFor for posts -->
<div class="container" *ngFor="let post of posts; let i = index">
<div class="row" style="border-top: 2px solid #ada5a5;">
<div class="col-md-12 col-md-offset-0" style=" height: auto; ">
<h6> {{post.description}} </h6>
</div>
</div>
<!--ngFor for likes -->
<div class="container" style="border: 0px solid #ada5a5; ">
<div class="row">
<!--like button-->
<div class=" col-4">
<div *ngFor="let like of postLikes; let j = index ">
<div *ngIf="( (postLikes.length != 0) && (post.user_id == like.user_id) && (post.post_id == like.post_id) && (like.like_status == 'like'))">
<button type="button" class="btn btn-success" (click)=likeSubmit(post.user_id,post.post_id)>Like</button><p>liked</p>
</div>
<div *ngIf="( (postLikes.length != 0) && (post.user_id == like.user_id) && (post.post_id == like.post_id) && (like.like_status == 'unlike'))">
<button type="button" class="btn btn-danger" (click)=likeSubmit(post.user_id,post.post_id)>Like</button><p>Disliked</p>
</div>
<div
*ngIf="( (postLikes.length == 0) && (post.user_id != like.user_id) && (post.post_id != like.post_id) && (like.like_status != 'unlike'))">
<button type="button" class="btn btn-warning" (click)=likeSubmit(post.user_id,post.post_id)>Like</button><p>Default</p>
</div>
</div>
</div>
</div>
</div>
</div>
<TypeScript>
export class AppComponent {
title = 'my-app';
name = 'Angular';
posts: any[] =
[{"post_id":4,"user_id":2,"description":" Hi How are you ","created_date":"2019-01-28T12:30:49.000Z"},{"post_id":5,"user_id":2,"description":" Working a Fine ","created_date":"2019-01-28T12:31:20.000Z"},{"post_id":6,"user_id":2,"description":" Hi How are you ......","created_date":"2019-01-28T12:32:15.000Z"},{"post_id":7,"user_id":2,"description":" 4th test post","created_date":"2019-01-29T07:10:37.000Z"},{"post_id":9,"user_id":2,"description":" 5th test post","created_date":"2019-01-31T11:17:31.000Z"},{"post_id":10,"user_id":2,"description":" 6th test post","created_date":"2019-01-31T12:03:54.000Z"},{"post_id":11,"user_id":2,"description":" 7th post post","created_date":"2019-02-08T05:50:02.000Z"},{"post_id":12,"user_id":2,"description":" 8th test post ","created_date":"2019-02-08T06:08:01.000Z"}];
postLikes:any[] =[{"post_id":4,"user_id":2,"like_status":"unlike","like_id":10},{"post_id":5,"user_id":2,"like_status":"like","like_id":9},{"post_id":6,"user_id":2,"like_status":"like","like_id":8},{"post_id":7,"user_id":2,"like_status":"like","like_id":7},{"post_id":9,"user_id":2,"like_status":"like","like_id":11}]
post_id: any;
// likes: Like[];
like_id: number | null ;
like_status: string;
constructor(private http: HttpClient, private formBuilder: FormBuilder){
}
ngOnInit() { }
// Get user details from DB
getPosts(user_id) {
this.userService.getPosts(user_id).subscribe((data) => {
this.posts = data;
},
error => {
return console.log(error);
}
);
}
// join postlikes
getPostLikes(user_id) {
// debugger
this.userService.get_PostLikes(user_id).subscribe((results) => {
this.postLikes = results;
// console.log(results, 'results', this.postLikes, 'likes');
},
error => {
return console.log(error);
}
);
}
Once check my link for live code editing in stackBlitz
https://stackblitz.com/edit/angular-wddupe?file=src%2Fapp%2Fapp.component.html
It's not working because *ngIf="(postLikes.length == 0) ... will never evaluate to true inside your <div *ngFor="let like of postLikes; let j = index ">
If postLikes.length == 0 then the *ngFor does not complete any iterations of the template.
In fact, all of the postLikes.length logic is actually unnecessary here.

How i show ViewBag value in my view page?

I have two class. Such as:
My controller code is shown below:
public class ResultController : Controller
{
private OnlineVotingSystemEntities db = new OnlineVotingSystemEntities();
// GET: Result
public ActionResult result()
{
var vp = (from c in db.Candidates
join v in db.VoterRegs
on c.UserReg equals v.UserRegNo
where c.CandidatePosition == "VP"
orderby c.Vote descending
select new {
UserPhoto = v.UserPhoto,
UserFirstName =v.UserFirstName,
UserRegNo = v.UserRegNo,
Vote = c.Vote
}).ToList();
ViewBag.VP1 = vp;
var gs = (from c in db.Candidates
join v in db.VoterRegs
on c.UserReg equals v.UserRegNo
where c.CandidatePosition == "GS"
orderby c.Vote descending
select new
{
UserPhoto = v.UserPhoto,
UserFirstName = v.UserFirstName,
UserRegNo = v.UserRegNo,
Vote = c.Vote
}).ToList();
ViewBag.GS1 = gs ;
var ags = (from c in db.Candidates
join v in db.VoterRegs
on c.UserReg equals v.UserRegNo
where c.CandidatePosition == "AGS"
orderby c.Vote descending
select new
{
UserPhoto = v.UserPhoto,
UserFirstName = v.UserFirstName,
UserRegNo = v.UserRegNo,
Vote = c.Vote
}).ToList();
ViewBag.AGS1 = ags;
var member = (from c in db.Candidates
join v in db.VoterRegs
on c.UserReg equals v.UserRegNo
where c.CandidatePosition == "Member"
orderby c.Vote descending
select new
{
UserPhoto = v.UserPhoto,
UserFirstName = v.UserFirstName,
UserRegNo = v.UserRegNo,
Vote = c.Vote
}).ToList();
ViewBag.Member1 = member;
return View();
}
}
My View Page is shown below:
#using OnlineVoting.Models
#{
ViewBag.Title = "result";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>result</h2>
<div class="container">
<h4>VP</h4>
<table cellpadding="2" cellspacing="2" border="1" class="dataTable">
<tr>
<th>Photo</th>
<th>User Name</th>
<th>Registration Number</th>
<th>Vote</th>
</tr>
#foreach (var item in ViewBag.VP1)
{
<tr>
<td><p><img src="data:image;base64,#Convert.ToBase64String(item.UserPhoto)" style="width:60px; height: 80px" class="VPimage" /></p></td>
<td>#item.UserFirstName</td>
<td>#item.UserRegNo</td>
<td>#item.Vote</td>
</tr>
}
</table>
</div>
<div class="container">
<h4>GS</h4>
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<th>Photo</th>
<th>User Name</th>
<th>Registration Number</th>
<th>Vote</th>
</tr>
#foreach (var item in ViewBag.GS1)
{
<tr>
<td><p><img src="data:image;base64,#Convert.ToBase64String(item.UserPhoto)" style="width:60px; height: 80px" class="VPimage" /></p></td>
<td>#item.UserFirstName</td>
<td>#item.UserRegNo</td>
<td>#item.Vote</td>
</tr>
}
</table>
</div>
<div class="container">
<h4>AGS</h4>
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<th>Photo</th>
<th>User Name</th>
<th>Registration Number</th>
<th>Vote</th>
</tr>
#foreach (var item in ViewBag.AGS1)
{
<tr>
<td><p><img src="data:image;base64,#Convert.ToBase64String(item.UserPhoto)" style="width:60px; height: 80px" class="VPimage" /></p></td>
<td>#item.UserFirstName</td>
<td>#item.UserRegNo</td>
<td>#item.Vote</td>
</tr>
}
</table>
</div>
<div class="container">
<h4>MEMBER</h4>
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<th>Photo</th>
<th>User Name</th>
<th>Registration Number</th>
#*<th>Vote</th>*#
</tr>
#foreach (var item in ViewBag.Member1)
{
<tr>
<td><p><img src="data:image;base64,#Convert.ToBase64String(item.UserPhoto)" style="width:60px; height: 80px" class="VPimage" /></p></td>
<td>#item.UserFirstName</td>
<td>#item.UserRegNo</td>
<td>#item.Vote</td>
</tr>
}
</table>
</div>
When I run this code then show the output:
Image 3 show the output of this code. I got an error. This error is : object does not contain a definition for UserPhoto. Why I got this type of error? Please help me.
In your controller, you are using anonymous object but I am suggesting to you to use strongly typed object and since you are using Viewbag, no need to cast in view. Like `
var vp = (from c in db.Candidates
join v in db.VoterRegs
on c.UserReg equals v.UserRegNo
where c.CandidatePosition == "VP"
orderby c.Vote descending
select new CandiateViewModel{
UserPhoto = v.UserPhoto,
UserFirstName =v.UserFirstName,
UserRegNo = v.UserRegNo,
Vote = c.Vote
}).ToList();

Resources