Sum of Row and Column . Sum of row is done but when do sum of column then is show sum of column same every textboxes - textbox

foreach (TSM.Models.Tasks itm in lstTasks.Where(x => x.Project.ID == item.ID).ToList())
{
<tr id="tmsData">
<td> </td>
<td>#itm.TaskName</td>
#for (int i = 1; i < 8; i++)
{
<td > <input class="txtTaskHours date#(Date.AddDays(i).ToString("MMddyyyy"))" style="width:50px;" type="number" id="#(itm.ID.ToString() + ':' + Date.AddDays(i).ToString("MMddyyyy"))" /></td>
}
<td><strong><input class="JKL" style="width:50px" /></strong></td>
</tr>
<tr>
</tr>
}
}
<tr>
<td></td>
<td></td>
#for (int i = 1; i < 8; i++)
{
<td ><strong><input class="JKLL " id="Tue" style="width:50px" /></strong></td>
}
<td></td><script>
$(document).ready(function () {
$(".txtTaskHours").on('keyup change', calculateSum);
});
function calculateSum() {
var $input = $(this);
var $row = $input.closest('tr');
var sum = 0;
$row.find(".txtTaskHours").each(function () {
sum += parseFloat(this.value) || 0;
});
$row.find(".JKL").val(sum.toFixed(2));
//adding column values
var eid = ($input.attr('id'));
var arrTaskTextBoxes = $('.date' + eid.substr(eid.indexOf(":") + 1, 8));
var sum = 0.00
for (var i = 0; i < arrTaskTextBoxes.length; i++) {
if (arrTaskTextBoxes[i].value != '') {
sum+= parseFloat(arrTaskTextBoxes[i].value) || 0;
}
}
$(".JKLL").val(sum.toFixed(2));
//document.getElementById('Tue').value = sum.toFixed(2);
console.log(sum);
}
This is my script code i tried this but when sum of column is take
place then if we fill data in top to bottom then its show sum in whole of the
textbox. Row sum is done very properly way but sum of the column issue is
coming sum of column show is correct but is sow all the text boxes that is
give in the bottom row. I use this script method here i am using eid by which
id of every textbox we take.

Related

ASP.NET razor engine seems retard [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a view that contains nothing but the following:
<table>
#for (int i = 0; i < 10; i++)
{
if (i % 5 == 0)
{
<tr>
}
<td>
Hello
</td>
if (i % 5 == 0)
{
</tr>
}
}
</table>
I intended to produce is the following
<table>
<tr>
<td>Hello</td>
<td>Hello</td>
<td>Hello</td>
<td>Hello</td>
<td>Hello</td>
</tr>
<tr>
<td>Hello</td>
<td>Hello</td>
<td>Hello</td>
<td>Hello</td>
<td>Hello</td>
</tr>
</table>
But instead it produced the following:
<table>
<tr>
}
<td>
Hello
</td>
if (i % 5 == 0)
{
</tr>
<tr>
}
<td>
Hello
</td>
if (i % 5 == 0)
{
</tr>
</table>
What is wrong?
You have to prefix any HTML you wish to show on the page with #: when it is within a code block
<table>
#for (int i = 0; i < 10; i++)
{
if (i % 5 == 0)
{
#:<tr>
}
#:<td>
#:Hello
#:</td>
if (i % 5 == 0)
{
#:</tr>
}
}
</table>
#for (int i = 0; i < 10; i++)
{
if (i % 5 == 0)
{
#:<tr>
}
<td>
Hello
</td>
if (i % 5 == 0)
{
#:</tr>
}
}
</table>
To produce the desired output you actually want the following:
<table>
#for (int i = 0; i < 10; i++)
{
if (i % 5 == 0)
{
#:<tr>
}
#:<td>
#:Hello
#:</td>
if ((i + 1) % 5 == 0)
{
#:</tr>
}
}
</table>
Notice the change to the second if statement. Alternatively you could use nested for loops to produce the same result.
<table>
#for (int i = 0; i < 2; i++)
{
<tr>
#for (int j = 0; j < 5; j++)
{
<td>Hello</td>
}
</tr>
}
</table>
You're code block should is across multiple lines so should be within braces (braces after the #)
#{
for (int i = 0; i < 10; i++)
{
Blah blah...
}
}

Highcharts graph shows 265 series and no data after update to categories and series

I inherited a small project that worked clunky and was actually quite wrong in its implementations and it almost has me tearing my head out.
http://stockfractions.com/doittest.php?TimeType=2&StartTimeFrameID=10&EndTimeFrameID=20&CompanyID=91,89&MetricID=2,3
What I am trying to do is to control what is shown on the graph so that i can export the final graph and dataset. The script basically does a pivot query in MySQL and then divides the data up by timeframe increments on the resultant page. Clicking the individual checkboxes changes whether than timeframe is part of the graph. However, every time I change the graph contents, it just shows a bunch of legends at the bottom for series going from 1 to 265 and no data. I have the code spitting out both the categories for the x-axis and the series data being passed to make sure that I am not losing my mind.
function setDynamicChart(chartCategories, chartData){
alert(chartCategories + '\n' + chartData);
$('#container123').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Fundamental Company Analysis'
},
plotOptions: {
line: {
dataLabels: {
enabled: false
},
enableMouseTracking: true
}
},
xAxis: {
categories: chartCategories
},
series: chartData
});
}
is the function to change the graphdata
function regen(){
var datacount = parseInt(document.f1.datacount.value);
var linecount = parseInt(document.f1.linecount.value);
var xnames = [];
mst = document.getElementById('metrics').value;
var metricnames = mst.split(",");
var sseries = "";
//rebuild
cats = "";
for(a = 1; a <= linecount; a++){
xnames[a] = document.getElementById('name_'+a).value;
for(b = 1; b <= metricnames.length; b++){
temp = ""
for(z = 1; z <= datacount; z++){
if(document.getElementById('set_'+z).checked){//deals with datacount
if(a==1 && b==1 )
cats = cats + "'" + document.getElementById('TimeFrame'+z).value + "',";
temp = temp + document.getElementById('data_' + a + '_' + z + '_' + b).value + ",";
}
}
sseries = sseries + "{ name: '" + xnames[a] + "-" + metricnames[b-1] + "', data: [" + removeLastComma(temp) + "]}, "
}
}
cats = '[' + removeLastComma(cats) + ']';
sseries = '[' + removeLastComma(sseries) + ']';
//setDynamicChart(eval("cats"),eval("sseries"));
setDynamicChart(cats,sseries);
}
is the code to regenerate the graph.
Here is an example of the code produced
<form name='f1' id='f1'>
<div id='mytablee_data'>
<input id='set_1' type='checkbox' value='1' onclick='regen();' checked='checked' style='top:-2px;position:relative;vertical-align: middle;margin-right: 9px'/>
<input type='hidden' value='2005FY' id='TimeFrame1'>
2005FY Data
<table id='mytablee_1' class='tablesorter' border='1'>
<thead><tr><th align='center'>Company</th><th align='center'>Accounts Payable</th><th align='center'>Accounts Receivable</th></tr>
</thead>
<tbody>
<tr align='right'><td style='width:auto' align='left'>Advanced Micro Devices</td><td style='width:auto'>856</td><td style='width:auto'>0</td></tr>
<tr align='right'><td style='width:auto' align='left'>Amazon</td><td style='width:auto'>1366</td><td style='width:auto'>0</td></tr></tbody></table><p></p>
<input id='set_2' type='checkbox' value='2' onclick='regen();' checked='checked' style='top:-2px;position:relative;vertical-align: middle;margin-right: 9px'/>
<input type='hidden' value='2006FY' id='TimeFrame2'>
2006FY Data
<table id='mytablee_2' class='tablesorter' border='1'>
<thead><tr><th align='center'>Company</th><th align='center'>Accounts Payable</th><th align='center'>Accounts Receivable</th></tr>
</thead>
<tbody>
<tr align='right'><td style='width:auto' align='left'>Advanced Micro Devices</td><td style='width:auto'>1338</td><td style='width:auto'>0</td></tr>
<tr align='right'><td style='width:auto' align='left'>Amazon</td><td style='width:auto'>1816</td><td style='width:auto'>-103</td></tr></tbody></table><p></p>
<input id='set_3' type='checkbox' value='3' onclick='regen();' checked='checked' style='top:-2px;position:relative;vertical-align: middle;margin-right: 9px'/>
<input type='hidden' value='2007FY' id='TimeFrame3'>
2007FY Data
<table id='mytablee_3' class='tablesorter' border='1'>
<thead><tr><th align='center'>Company</th><th align='center'>Accounts Payable</th><th align='center'>Accounts Receivable</th></tr>
</thead>
<tbody>
<tr align='right'><td style='width:auto' align='left'>Advanced Micro Devices</td><td style='width:auto'>1009</td><td style='width:auto'>0</td></tr>
<tr align='right'><td style='width:auto' align='left'>Amazon</td><td style='width:auto'>2795</td><td style='width:auto'>-255</td></tr></tbody></table><p></p>
<input type='hidden' name='linecount' value='2'>
<input type='hidden' name='datacount' value='3'>
<input type='hidden' id='metrics' value="Accounts Payable,Accounts Receivable">
<input type='hidden' value='Advanced Micro Devices' id='name_1'>
<input type='hidden' value='856' id='data_1_1_1'>
<input type='hidden' value='1338' id='data_1_2_1'>
<input type='hidden' value='1009' id='data_1_3_1'>
<input type='hidden' value='0' id='data_1_1_2'>
<input type='hidden' value='0' id='data_1_2_2'>
<input type='hidden' value='0' id='data_1_3_2'>
<input type='hidden' value='Amazon' id='name_2'>
<input type='hidden' value='1366' id='data_2_1_1'>
<input type='hidden' value='1816' id='data_2_2_1'>
<input type='hidden' value='2795' id='data_2_3_1'>
<input type='hidden' value='0' id='data_2_1_2'>
<input type='hidden' value='-103' id='data_2_2_2'>
<input type='hidden' value='-255' id='data_2_3_2'></div>
</form>
The data elements go by the company, timeframe, metric so as to easily parse for selection changes
Well.. first of all I would advice you to read some tutorials about JS. Otherwise you will lose all hairs. Mainly problem is with regen() function. In short, you are generating JSON string manually, for some unknown reason (too much PHP?).
I would upgrade your method:
function regen(){
var datacount = parseInt(document.f1.datacount.value);
var linecount = parseInt(document.f1.linecount.value);
var xnames = [];
mst = document.getElementById('metrics').value;
var metricnames = mst.split(",");
// series and categories in Highcharts should be arrays
var sseries = [],
cats = [];
for(a = 1; a <= linecount; a++){
xnames[a] = document.getElementById('name_'+a).value;
for(b = 1; b <= metricnames.length; b++){
// data in series should be an array too
temp = [];
for(z = 1; z <= datacount; z++){
if(document.getElementById('set_'+z).checked){//deals with datacount
if(a==1 && b==1 ) {
//push categories to the array
cats.push(document.getElementById('TimeFrame'+z).value);
}
// Highcharts requires values to be number, not a string -> parse that string to the value
temp.push(parseFloat(document.getElementById('data_' + a + '_' + z + '_' + b).value));
}
}
// generate series objects
sseries.push({ name: xnames[a] + "-" + metricnames[b-1], data: temp});
}
}
setDynamicChart(cats,sseries);
}
Extra advice: To debug JS, don't use alert(), but rather console.log() - it's easier to deal with developer tools, than some string in the alert popup.
Thanks so much. I saw something else online and took out the brackets for data. Here is the code in case anyone else is suffering the same way, and thanks Pawel for pointing me in the right direction.
function regen(){
var datacount = parseInt(document.f1.datacount.value);
var linecount = parseInt(document.f1.linecount.value);
var xnames = [];
mst = document.getElementById('metrics').value;
var metricnames = mst.split(",");
var sseries = [], cats = [];
for(a = 1; a <= linecount; a++){
xnames[a] = document.getElementById('name_'+a).value;
for(b = 1; b <= metricnames.length; b++){
temp = [];
for(z = 1; z <= datacount; z++){
if(document.getElementById('set_'+z).checked){//deals with datacount
if(a==1 && b==1 )
cats.push(document.getElementById('TimeFrame'+z).value);
temp.push(parseFloat(document.getElementById('data_' + a + '_' + z + '_' + b).value));
}
}
var itemx = {
name: "'" + xnames[a] + "-" + metricnames[b-1] + "'",
data: temp
};
sseries.push(itemx);
}
}
setDynamicChart(cats,sseries);
}

ASP.NET MVC4 FormCollection.GetValues not returning correct values

I'm building a mobile webiste using ASP.NET MVC4.
One of the pages in my solution contains a table where all the rows in the table can be edited and saved in one batch. To do this I am using FormCollection in the Action in the Controller. This works as expected for most of the fields, exept one: item.IsPercent. This field is a boolean, and FormCollection.GetValues("item.IsPercent") returns twice the number of rows in the table and the list always alternates between true and false, no matter what the actual values are.
How can I collect the right value for the Percent checkboxes?
An Example
My View
#using (Html.BeginForm()) {
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
foreach (var group in Model.GroupBy(i => i.Exercise.Name)) {
<table>
<tr>
<th colspan="4">#Html.Label(group.Key)</th>
</tr>
<tr>
<td>Load</td>
<td>Percent</td>
<td> </td>
<td>Reps</td>
</tr>
#foreach (var item in group.OrderBy(i => i.Order))
{
#Html.HiddenFor(modelItem => item.Id)
<tr>
<td>
#Html.EditorFor(modelItem => item.Load)
#Html.ValidationMessageFor(modelItem => item.Load)
</td>
<td>
#Html.EditorFor(modelItem => item.IsPercent)
</td>
<td>
x
</td>
<td>
#Html.EditorFor(modelItem => item.Repetitions)
#Html.ValidationMessageFor(modelItem => item.Repetitions)
</td>
</tr>
}
</table>
<br />
}
<p>
<input type="submit" value="Save" />
</p>
}
My Controller
[HttpPost]
public ActionResult EditProgramTemplateLines(FormCollection c)
{
int i = 0;
int ptId = 0;
if (ModelState.IsValid)
{
var ptIdArray = c.GetValues("item.id"); // [1,2,3,4]
var ptLoadArray = c.GetValues("item.Load"); // [50, 55, 60, 80]
var ptPercentArray = c.GetValues("item.IsPercent"); // [true, false, true, false, true, false, true, false]
var ptRepsArray = c.GetValues("item.Repetitions"); // [13, 10, 5, 2]
for (i = 0; i < ptIdArray.Count(); i++) {
var ptLine = factory.GetProgramTemplateLine(Convert.ToInt32(ptIdArray[i]));
if(ptId == 0)
ptId = ptLine.ProgramTemplateId;
ptLine.Load = ConvertToDouble(ptLoadArray[i]);
ptLine.IsPercent = Convert.ToBoolean(ptPercentArray[i]);
ptLine.Repetitions = ConvertToInt(ptRepsArray[i]);
factory.SetEntryAsModified(ptLine);
}
factory.SaveChanges();
return RedirectToAction("Details", new { id = ptId });
}
return View();
}
Updated solution
Considering the link posted in comment below FormCollection for a checkbox my solution is to loop throug the array like this:
var percentId = 0;
for(i = 0;i<ptIdArray.Count();i++){
if(ptPercentArray[percentId] == true){
item.IsPercent = true;
percentId = percentId + 2;
}
else{
item.IsPercent = false;
percentId++;
}
}
Take a look at the HTML generated for the Html.EditorFor! The helpers create one checkbox and one hidden field for each checkbox to make state management easily at server side! Thats the problem! Using FormCollection as parameter you need to differentiate the hidden from the real checkbox to get the value!
Hopes this help you!

How to select the all the rows in jquery data table

I have two buttons in my page "Select All" and "Deselect All". I need to select the all the rows when i click the select all button and save the list of id in my variable. When Click deselect ll button it should be deselect the all rows . How will we do that?
[HttpPost]
public ActionResult Action Name(pssing value)
{
DataTable dataTable = new DataTable();
// my code
var MyModel = new List<List<string>>();
foreach (var joblist in Jobs)
{
var sublist = new List<string>();
sublist.Add(checked.false);
sublist.Add(values));
sublist.Add(values));
....etc
baseModel.Add(sublist);
}
return new DataTableResult(return);
}
Html :
<table cellpadding="0" cellspacing="0" border="0" class="display" id="AssignJobsTable" width="100%">
<thead>
<tr>
<th><input type="checkbox" id="selectall"/></th>
<th>ID</th>
etc ......
</tr>
</thead>
script:
$(function(){
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
});
// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(".case").click(function(){
if($(".case").length == $(".case:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
When i click the select all check box it cant bind the value form the controller.
try this
$('table#tableId> tbody > tr').addClass('highlight');
$('table#tableId> tbody > tr').removeClass('highlight')addClass('noHeilight');
sample table
<table border="1">
<tr>
<th><input type="checkbox" id="selectall"/></th>
<th>Cell phone</th>
<th>Rating</th>
</tr>
<tr>
<td align="center"><input type="checkbox" class="case" name="case" value="1"/></td>
<td>BlackBerry Bold 9650</td>
<td>2/5</td>
</tr>
<tr>
<td align="center"><input type="checkbox" class="case" name="case" value="2"/></td>
<td>Samsung Galaxy</td>
<td>3.5/5</td>
</tr>
</table>
sample script:
$(function(){
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
});
// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(".case").click(function(){
if($(".case").length == $(".case:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
you should set id attr for checkboxes and put row id in the id attr and use the below code for selecting and deselecting:
$(document).ready(function(){
$("#selectall").click(function () {
var isSelect;
if($(this).is(":checked")) {
isSelect=true;
}else{
isSelect=false;
}
$("table tr td input[type=checkbox]").each(function(){
if(isSelect) {
$(this).prop('checked', true);
SelectedItems+=$(this).val()+":";
}else{
$(this).prop('checked', false);
SelectedItems="";
}
$("#Result").html(SelectedItems);
});
});
});
This is my approach of keeping track of all the selected rows in a datatable.
http://www.datatables.net/release-datatables/examples/plug-ins/plugin_api.html
The idea is to check the current page that the user is on and select/deselect the rows that is currently being viewed. You would loop through the page's rows and store the selected row into an array for future reference.
With this approach you would limit the time it takes to select/deselect all rows in the table.
Only show whats needed base on the view that user is seeing.
No hang up because the table is too busy checking/unchecking each row.
//stored checked box list
var result = [];
var selectAll = false;
var table5 = $('#example5').dataTable({
'fnDrawCallback':function(oSettings){
var anNodes = this.oApi._fnGetTrNodes( oSettings );
var anDisplay = $('tbody tr', oSettings.nTable);
//write your logic for pagination
//example
/*
$('tbody tr td:first-child input[type=checkbox]').on('click', function(){
if($(this).is(':checked')){
if($.inArray(....) != -1){push result}
}else{
if($.inArray(....) != -1){splice result}
}
}
if(selectAll){
for(var i = 0; i < anDisplay.length; i++){
//check if it's in result array
//add to the array
}
}else{
for(var i = 0; i < anDisplay.length; i++){
//check if it's in result array
//delete from the array
}
}
*/
}
})
That would be your logic for keeping track of the checked row.

MVC formatting td dynamically

I am new to razor engine syntax and I have issue with formatting adding the logic in the view. Here is what I want to accomplish. I have collection of items coming from model.
I need to iterate that collection and align 6 item in a row.
This is how the final output should look like:
<table>
<tr>
<td>checkbox comes here</td>
<td>checkbox comes here</td>
<td>checkbox comes here</td>
</tr>
<tr>
<td>checkbox comes here</td>
<td>checkbox comes here</td>
<td>checkbox comes here</td>
</tr>
................. and so on
</table>
Here is the code I wrote in the view
<table>
#for (int i = 0; i <= Model.checkItems.Count; i++)
{
if (i % 6 == 0)
{ <tr> }
<td>
<input type="checkbox"
id="chk_#(Model.checkItems[i].DisplayText)"
name="chk"
nameVal = "#Model.checkItems[i].DisplayText"
value="#Model.checkItems[i].Value"/>
<label for="chkGroup_#(Model.checkItems[i].DisplayText)">#Model.checkItems[i].DisplayText
</td>
if(i % 6 == 0)
{ </tr> }
}
</table>
When the page finally gets rendered, the first if condition getting executed but not the second one.
Can somebody help to figure out how the accomplish this?
Try this
<table>
#{ int count = 0; }
<tr>
#foreach (var item in Model.checkItems)
{
<td>
<input type="checkbox"
id="chk_#(item.DisplayText)"
name="chk"
nameVal = "#item.DisplayText"
value="#item.Value"/>
<label for="chkGroup_#(item.DisplayText)">#item.DisplayText</label>
</td>
if (++count % 6 == 0)
{
#:</tr><tr>
}
}
</tr>
</table>
You're missing a closing tag on your label
<label for="chkGroup_#(Model.checkItems[i].DisplayText)">#Model.checkItems[i].DisplayText
should be
<label for="chkGroup_#(Model.checkItems[i].DisplayText)">#Model.checkItems[i].DisplayText</label>
would this work:
<table>
#for (int i = 0; i <= Model.checkItems.Count; i++)
{
if (i % 6 == 0)
{
<tr>
<td>
<input type="checkbox"
id="chk_#(Model.checkItems[i].DisplayText)"
name="chk"
nameVal = "#Model.checkItems[i].DisplayText"
value="#Model.checkItems[i].Value"/>
<label for="chkGroup_#(Model.checkItems[i].DisplayText)">#Model.checkItems[i].DisplayText
</td>
</tr>
}
}
</table>
Here's another solution that uses 2 nested loops for rows and columns. I don't know if its necessarily better (it certainly looks more complicated on the face of it), but it does at least allow you to easily see the nested nature of the rows and cells:
<table>
#{
const int cols = 3;
int rows = (Model.checkItems.Count + cols - 1) / cols;
}
#for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
<tr>
#for (int colIndex = rowIndex * cols; colIndex < Math.Min(Model.checkItems.Count, cols * (rowIndex + 1)); colIndex++)
{
<td>
<input type="checkbox"
id="chk_#(Model.checkItems[colIndex].DisplayText)"
name="chk"
nameVal="#Model.checkItems[colIndex].DisplayText"
value="#Model.checkItems[colIndex].Value"/>
<label for="chkGroup_#(Model.checkItems[colIndex].DisplayText)">#Model.checkItems[colIndex].DisplayText</label>
</td>
}
</tr>
}
</table>

Resources