I need to display data like below
+------+----------+----------+----------+
| Name | Subject1 | Subject2 | subject3 |
+------+----------+----------+----------+
| A | 20 | 30 | 40 |
| B | 21 | 31 | 41 |
| C | 2 | 3 | 4 |
+------+----------+----------+----------+
I used spring mvc. I created a model - Student.Java
import java.util.ArrayList;
public class Student {
ArrayList<String> markList;
public ArrayList<String> getMarkList() {
return markList;
}
public void setMarkList(ArrayList<String> markList) {
this.markList = markList;
}
}
I used ResponseBody and returned List for that method. I used ajax call and got the JSON response as below
[{"markList":["name","subject1","subject2","subject3"]}{"markList": ["A",20","30","40"]},{"students":["B",21","31","41"]},{"students":["C",2","3","4"]}]
In my Angularjs controller i just used a ajax call and assigned as below
var reponseData= reponse.data;
var studentarray;
var marklist;
for(var i=0;i<responseData.length;i++){
studentarray.push(responseData[i]);
}
for(var j=0;j<studentarray.length;j++){
marklist.push(studentarray[j].markList);
}
$scope.studentslist=marklist;
My jsp code
{{col}}
But I am not getting the desired result.Can somebody help me how to design the model and access it in js. Please help
You don't need to re-iterate an array an create a new array on the page, just directly assigns response.data to studentslist. You could just use ng-repeat to render a table on page.
<table class="table table-bordered">
<tr ng-repeat="list in studentslist">
<td ng-repeat="mark in list.markList">{{mark}}</td>
</tr>
</table>
Related
My dexiedb structure looks like below.
const db = new Dexie('shipment-execution');
db.version(1).stores({
root: '++id,shipmentid,stopid',
})
My IndexedDB will look like below
| id| shipmentid| stopid|
| 1 | 6000001 | 10 |
| 2 | 6000001 | 20 |
| 3 | 6000001 | 30 |
| 4 | 6000002 | 10 |
| 5 | 6000002 | 20 |
I am trying to get all the data which has shipmentid equal to 6000001. Each time it is returning only one record (the first record ).
db.root.where({shipmentid : '6000001'}).toArray().then((d)=>{
console.log(d);
})
output is only fetching the first record
| id| shipmentid| stopid|
| 1| 6000001 | 10 |
Please let me know, what I am doing wrong.
I have Table (Employees) A:
+----+---------+
| ID | NAME |
+----+---------+
| 1 | ROBERT |
| 2 | JAMES |
| 3 | RICHARD |
| 4 | KANYE |
| 5 | DYLAN |
| 6 | JOHN |
| 7 | JEAN |
| 8 | LOKI |
| 9 | ADAM |
+----+---------+
And Table (Employees) B:
+----+---------+
| ID | NAME |
+----+---------+
| 1 | ROBERT |
| 2 | JAMES |
| 3 | RICHARD |
| 4 | KANYE |
| 5 | DYLAN |
+----+---------+
Those people are my "employees". The names from table B are all the employees on my database and the names from table A are all the employees that I've assigned to project n°1.
I would like to HIDE all names in Table B that already appear in Table A because I don't want to re-assign the same employee to project n°1.
How can I resolve this using jQuery?
a clientside check would be:
function compareLists(listA, listB){
var resultList = [];
listA.forEach(function(itemA){
listB.forEach(function(itemB){
if (itemB.name !== itemA.name)resultList.push(itemB);
}
}
return resultList;
}
or at the serverside (database):
select * from table_b where name not in (select name from table_a)
greetings
Normally you should do that on the server side using SQL as already answered. However, since you ask about javascript. This is the way to filter it at client side:
//collect list of names in A
var table = document.getElementById("TableA");
var names = []
for (var i = 0, row; row = table.rows[i]; i++) {
names.push(row.celss[1]);
}
//check names in B
table = document.getElementById("TableB");
for (var i = 0, row; row = table.rows[i]; i++) {
if(jQuery.inArray(row.cells[1], names) !== -1){
//show row
}else{
//hide row
}
}
I dont have that much knowlwdge in Jquery..
But this query increases perfomance in a large DB.
SELECT
FROM TableB
LEFT JOIN TableA ON TableB.name=TableA.name // id will be better than name
WHERE TableB.name IS NULL
Hope this helps
I'm trying to figure out how to create a nested JSON object, something like this:
company: "Company 1",
pricing: {
term: "1 year",
price: "$4.95",
term: "2 years",
price: "3.95"
},
I have two tables in MySQL, one called plans which is structured in this fashion
| id | company |
------------------
| 2 | company 1 |
and another table plans_pricing to represent the pricing data
| id | plans_id | term | price |
--------------------------------
| 1 | 2 | 1 year | $4.95 |
| 2 | 2 | 2 years| $3.95 |
I am using Laravel 4 to query the database and create json to send back to my ajax request. Here is the query, which is currently sending a server 500 error.
public function results()
{
$answers = $_POST['answers'];
$data = DB::table('plans')
->join('plans_pricing', 'plans.id', '=', 'plans_pricing.plans_id')
->select('plans.company', 'plans_pricing.price', 'plans_pricing.term')
->whereIn('plans.id', $answers)
->get();
echo json_encode($data);
}
I'm not sure why this query isn't working, but that isn't even why i'm asking this question. I need to know how to get a nested JSON object, when I create the join, I believe that I'll receive a separate object for each, like here:
| company | price | term |
------------------------------------
| company 1 | 4.95 | 1 year |
| company 1 | 3.95 | 2 years|
How can I make this SQL query return a nested JSON object like the one I describe above? I have been stuck on this problem for two days now and could really use some guidance. Thanks
UPDATE:
The server 500 error was fixed by changing echo json_encode to return Response::json($data);
I've never used Laravel but I think this should work:
$output = array();
$currentCompany = "";
foreach ($data as $datum) {
if ($datum->company != $currentCompany) {
$output[] = array();
// get a reference to the newly added array element
end($output);
$currentItem = & $output[key($output)];
$currentCompany = $datum->company;
$currentItem['company'] = $currentCompany;
$currentItem['rates'] = array();
}
$currentItem['rates'][] = array("price" => $datum->price, "term" => $datum->term);
}
json_encoded result:
[{
"company":"company 1",
"rates":[{
"price":4.95,"term":"1 year"
},{
"price":3.95,"term":"2 years"
}]
}]
Good day! How to parse JSON tree structure using EXTjs to bring them to the table view? Below is the structure that I want to put it to grid, how to do it? How to set up the model and storage?
[
{"WorckGroup":"3D",
"Statistics":[
{"Specialist":"V A K","SCallCount":64,"AverageDuration":0.1136067},
{"Specialist":"K T A","SCallCount":170,"AverageDuration":0.1057270},
{"Specialist":"L A V","SCallCount":71,"AverageDuration":0.4269940}]},
{"WorckGroup":"GPSK",
"Statistics":[
{"Specialist":"B A V","SCallCount":60,"AverageDuration":0.1109374},
{"Specialist":"K K A","SCallCount":17,"AverageDuration":0.1125816}]},
{"WorckGroup":"RG",
"Statistics":[
{"Specialist":"K A F","SCallCount":128,"AverageDuration":0.0624402},
{"Specialist":"O A V","SCallCount":115,"AverageDuration":0.3808017},
{"Specialist":"F E U","SCallCount":74,"AverageDuration":0.2172953}]}
]
| 3D | V A K | 64 | 0.1136067 |
| 3D | K T A | 170 | 0.1057270 |
...
| RG | F E U | 74 | 0.2172953 |
That data structure looks to be good for a tree grid.
http://docs.sencha.com/extjs/4.2.1/#!/example/build/KitchenSink/ext-theme-neptune/#tree-grid
Otherwise you could process the response in an ajax request to loop through the data and use the loadData method in a store.
I'm trying to create ListView which contains ASPxTextBox that the user can enter only numeric value. There are many rows and columns of data. I want to add new row and column that calculate total value from each row and column
For example, if I have data like this:
Student Name | Subject1 | Subject2 | Subject3
----------------------------------------------------------
John ----------- | ------- 23 | --------45 | --------37
Smith ---------- | ------- 41 | --------22 | --------11
Linda ---------- | ------- 35 | --------38 | --------23
I want to be like this
Student Name | Subject1 | Subject2 | Subject3 | Total
------------------------------------------------------------------
John ----------- | ------- 23 | --------45 | --------37 | 105
Smith ---------- | ------- 41 | --------22 | --------11 | --74
Linda ---------- | ------- 35 | --------38 | --------23 | --96
------------------------------------------------------------------
Total----------- | --------99 | -------105 | --------71 | 275
The number of columns (Subject) is fixed but the number of rows depends on data in database.
There are 2 main problems here:
1. I want the summation row and column to execute calculation in client side using javascript. So when one of textboxes is lost focus, it will recalculate the summation value in each row and column.
2. I can't access the value from ASPxTextBox using javascript. I tried using:
var test = document.getElementById('<%# Container.FindControl("txt_Subject1").ClientID %>')
var data = test.value;
but it doesn't seem to work.
The following code also cause error:
var test = document.getElementById('<%# Container.FindControl("txt_Subject1").ClientID %>')
var data = test.GetValue();
And when I tried ClientInstanceName, it always return the value of the last row only:
var data = txt_Subject1.GetValue(); //doesn't work?
Also, I don't want to change ASPxTextBox to asp TextBox because I want to use some of its feature.
You could dinamically assign ClientInstanceName values based on row number:
txt_Subject1_1
txt_Subject1_2
...
txt_Subject1_n
Then use javascript to calculate sum:
var sum = 0;
for (var i = 1; i <= rowCount; i++)
{
sum += parseInt(window['txt_Subject1_' + i].GetValue());
}