How to select all checkboxes in JHipster - jhipster

I created test Spring Boot + AngularJS app to test checkboxes:
html:
... <thead>
<tr>
<th><input type="checkbox" ng-model="isAllSelected"
ng-click="selectAll()"></th>
<th>Lp.</th>
<th>ID</th>
<th>Name</th>
<th>Parent Id</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="test in tests">
<td><input type="checkbox" ng-model="test.checked"
ng-change="optionSelected()" /></td>
<td>{{$index+1}}.</td>
<td>{{test.id}}</td>
<td>{{test.name}}</td>
<td>{{test.parentId}}...
test_controller.js:
(function(angular) {
var AppTestController = function($scope, Test) {
var vm = this;
vm.tests = [];
vm.loadAll = loadAll;
loadAll();
function loadAll() {
Test.query(function(result) {
vm.tests = result;
});
}
vm.selectAll = function() {
var toggleStatus = vm.isAllSelected;
angular.forEach(vm.tests, function(itm) {
itm.checked = toggleStatus;
});
}
vm.optionSelected = function() {
vm.isAllSelected = vm.tests
.every(function(itm) {
return itm.checked;
})
}
};
AppTestController.$inject = [ '$scope', 'Test' ];
angular.module("myApp.test_controller").controller(
"AppTestController", AppTestController);
}(angular));
This works for me as spring Boot app, but when I do the same in JHipster it doesn't work.
How can I get it to work in JHipster?

This is what I currently used and it works!:
.html
<thead>
<tr jh-sort="vm.predicate" ascending="vm.reverse" callback="vm.transition()">
<!--th jh-sort-by="id"><span data-translate="global.field.id">ID</span> <span class="glyphicon glyphicon-sort"></span></th-->
<th><input type="checkbox" icheck ng-change="vm.selectAll()" ng-model="vm.checkAll[vm.page]"></th>
<th jh-sort-by="id"><span data-translate="global.field.id">ID</span></th>
---
</tr>
</thead>
<tbody>
<tr ng-repeat="school in vm.schools track by school.id">
<td><input type="checkbox" icheck ng-model="vm.checkboxes[school.id]" ng-change="vm.select(school)"/></td>
<td>{{($index + 1) + (vm.page - 1) * vm.itemsPerPage}}</td>
...
</tr>
</tbody>
.js
vm.checkAll = [];
var map = {};
vm.checkboxes = [];
vm.selectedItems = [];
vm.selectAll = selectAll;
vm.select = select;
function selectAll () {
var value = vm.checkAll[vm.page];
angular.forEach(vm.schools, function(item) {
if (angular.isDefined(item.id)) {
if(vm.checkboxes[item.id] != value) {
vm.checkboxes[item.id] = value;
vm.select(item);
}
}
});
};
function select (item) {
var value = vm.checkboxes[item.id];
if(value) {
vm.selectedItems.push(item);
if(map[vm.page] == null) map[vm.page] = 1;
else map[vm.page] = map[vm.page] + 1;
if(map[vm.page] == vm.schools.length) {
vm.checkAll[vm.page] = true;
}
} else {
vm.selectedItems.splice(item, 1);
if(map[vm.page] == null) map[vm.page] = 0;
else map[vm.page] = map[vm.page] - 1;
if(map[vm.page] < vm.schools.length) {
vm.checkAll[vm.page] = false;
}
}
};

Related

LWC Pagination with page number

I'm a junior developer, I need some help to implement an lwc component which display records in experience site so I need to implement pagination since we have a large number to record.
I implement the 2 buttons "Previous" and "Next" it works fine, but I need the a clickable number o page between the 2 buttons here is the mockup : something like :<- 1 2 3 4 ... ->
here is my code:
<template>
<div class="pastcfps"><br>
<table>
<thead>
<tr>
<th class="pastcfpstitle"></th>
<th class="fullProposalDeadlineTitle"><a data-id="Proposal_Submission_Deadline__c"
onclick={sort}>Closing Date<img src={sortArrowUp} data-id="sortIconFp"></a></th>
</tr>
</thead>
<tbody>
<template if:true={pastcfps}>
<template for:each={pastcfps} for:item="pastcfp">
<tr class="pastcfpstr" key={pastcfp.Id}>
<td key={pastcfp.Id} class="pastcfpstitle">
<p class="pastcfpsRecordType">{pastcfp.RecordType.Name}</p>
<a class="pastcfpsname" data-id={pastcfp.Id} onclick={redirect} is-loading={tableLoadingState}>{pastcfp.Name}</a>
</td>
<td key={pastcfp.Id} class="fullProposalDeadline">{pastcfp.Proposal_Submission_Deadline__c}
</td>
</tr>
</template>
</template>
</tbody>
<template if:true={error}>
<p class="pastcfpsname">There are no past Calls for Proposals</p>
</template>
</table>
</div>
<div style="text-align:center;">
<c-pagination-navigation onprevious={handlePrev} onnext={handleNext}></c-pagination-navigation>
</div>
</template>
import { LightningElement, api, wire, track } from 'lwc';
import getPastCfPs from '#salesforce/apex/CallsForProposalsService.getPastCfPs';
import ARROW_LOGO from '#salesforce/contentAssetUrl/homearrow';
import SORT_ARROW_UP from '#salesforce/resourceUrl/sortArrowUp';
import SORT_ARROW_DOWN from '#salesforce/resourceUrl/sortArrowDown';
export default class RecentOpenCallsForProposals extends LightningElement {
arrowLogo = ARROW_LOGO;
sortArrowUp = SORT_ARROW_UP;
sortArrowDown = SORT_ARROW_DOWN;
sortedDirection = 'asc';
sortedColumn;
#track tableLoadingState = false;
#track pastcfps;
#track error
#track offset=0;
#track Prevoffset=0;
limit = 12;
#wire(getPastCfPs,{ offset: '$offset', l : '$limit' }) wiredCfps({ data, error }) {
this.tableLoadingState = false;
if (data) {
this.pastcfps = data;
console.log(' type of data =====| ' + typeof data);
console.log(' type of data 0 =====| ' + typeof data[0]);
console.log(' type of data =====| ' + typeof this.pastcfps);
console.log(' type of data 0 =====| ' + typeof this.pastcfps[0]);
let dataString = JSON.stringify(data[0]);
console.log(' dataString ========| ' + dataString);
console.log(' Name ========| ' + data[0].Name);
console.log(' Status__c ========| ' + data[0].Status__c);
console.log(' CreatedDate ========| ' + data[0].CreatedDate);
console.log(' Proposal_Submission_Deadline__c ========| ' + data[0].Proposal_Submission_Deadline__c);
this.error = undefined;
if(this.pastcfps.length == 0)
this.offset= this.Prevoffset;
} else if (error) {
this.error = error;
this.pastcfps = undefined;
}
}
handlePrev (_event) {
//window.clearTimeout(this.delayTimeout);
if(this.offset - this.limit >=0)
{
this.tableLoadingState = true;
this.Prevoffset=this.offset;
this.offset = this.offset - this.limit;
}
}
handleNext (_event) {
//window.clearTimeout(this.delayTimeout);
this.tableLoadingState = true;
this.Prevoffset=this.offset;
this.offset = this.offset + this.limit;
}
redirect(event) {
var id = event.currentTarget.dataset.id;
if (id) {
window.location = 'call-for-proposal/' + id;
}
}
sort(e) {
if (this.sortedColumn === e.currentTarget.dataset.id) {
this.sortedDirection = this.sortedDirection === 'asc' ? 'desc' : 'asc';
} else {
this.sortedDirection = 'asc';
}
let table = JSON.parse(JSON.stringify(this.pastcfps));
var reverse = this.sortedDirection === 'asc' ? 1 : -1;
try {
table.sort((a, b) => { return new Date(a[e.currentTarget.dataset.id]) > new Date(b[e.currentTarget.dataset.id]) ? 1 * reverse : -1 * reverse });
} catch (error) {
console.log(error);
}
this.sortedColumn = e.currentTarget.dataset.id;
this.pastcfps = table;
if (e.currentTarget.dataset.id == 'Proposal_Submission_Deadline__c') {
let existingIcon = this.template.querySelectorAll('img[data-id="sortIconFp"]');
if (existingIcon[0]) {
existingIcon[0].parentNode.removeChild(existingIcon[0]);
}
let nodes = this.template.querySelectorAll('a[data-id="' + e.currentTarget.dataset.id + '"]');
var icon = document.createElement('IMG');
if (this.sortedDirection === 'asc') { icon.setAttribute('src', this.sortArrowUp); }
if (this.sortedDirection === 'desc') { icon.setAttribute('src', this.sortArrowDown); }
icon.setAttribute('data-id', 'sortIconFp');
if (nodes[0]) { nodes[0].appendChild(icon); }
}
}
}
#AuraEnabled(cacheable=true)
public static List<Call_for_Proposal__c> getPastCfPs(Integer offset, Integer l){
String recordTypeName = [SELECT Id, Name, Status__c, CreatedDate, RecordTypeId, RecordType.Name, Proposal_Submission_Deadline__c FROM Call_for_Proposal__c WHERE Status__c = 'Closed' ].get(0).RecordType.Name;
system.debug('recordTypeName === ' + recordTypeName);
return [SELECT Id, Name, Status__c, CreatedDate, RecordTypeId, RecordType.Name, Proposal_Submission_Deadline__c FROM Call_for_Proposal__c WHERE Status__c = 'Closed' limit :l offset :offset];
}

Multiply two different numeric data in separate rows in react table

I am trying to multiply two different data fetched from the database and have the result displayed on a table. I am having issues multiplying data from two different rows and displaying the result on same table.
// code to filter and render table
renderTable() {
var totalCount = 0;
var shownCount = 0;
var lowerBound = 0;
var upperBound = 0;
var filtered = [];
filtered = this.state.data.map( (row, i,) => {
if(row.department.toLowerCase().indexOf(this.state.departmentFilter) > -1){
return (
<tr key={"employeeData"+i}>
<td>{i+1}</td>
<td>{row.name}</td>
<td>{row.numberofPresentAttendances}</td>
<td>{row.department}</td>
<td>{row.wages}</td>
<td>{row.totalWages}</td>
<td>
</td>
</tr>
);
} else {
return undefined;
}
});
<table className="employee-table">
<tbody>
<tr>
<th>No</th>
<th>Name</th>
<th>Attendance in the last 7days</th>
<th>Department</th>
<th>Wage/hr</th>
<th>Total Wages</th>
<th></th>
</tr>
{ filtered }
</tbody>
</table>
// mongoose models
var employeeSchema = mongoose.Schema({
name: String,
department: String,
wages:Number,
attendances: Object
},{timestamps:true});
var Employee = mongoose.model('Employee', employeeSchema);
I would like to multiply the Wages/hr and numberofPresentAttendances in the frontend
I am not sure if I understand your question completely but if you want to show the result of (numberofPresentAttendances * wages) then you can do something like this:
filtered = this.state.data.map( (row, i,) => {
if(row.department.toLowerCase().indexOf(this.state.departmentFilter) === -1){
return null;
}
return (
<tr key={"employeeData"+i}>
<td>{i + 1}</td>
<td>{row.name}</td>
<td>{row.numberofPresentAttendances}</td>
<td>{row.department}</td>
<td>{row.wages}</td>
<td>{row.numberofPresentAttendances * row.wages}</td>
</tr>
);
});
Although I am not sure why you are using variable numberofPresentAttendances instead of attendances as mentioned in your mongoose schema.

Click item in SharePoint using Knockout.js

I am trying to display details of a SharePoint document library using knockout.js.I want the name of the item or the URL to be clickable.Is it possible? I am trying below code but it is not formatting to URL link <a hrefr=# data-bind="attr: {href: Designation}, text:Designation"></a>
Below is the source code
<table id="tblEmployeeList" border="1">
<thead>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Department</th>
<th>Location</th>
</tr>
</thead>
<!-- Iterating through every list item using foreach of KO -->
<tbody data-bind="foreach: Employees">
<tr>
<td data-bind="text: Name"></td>
**<td </td>**
<td data-bind="text: Department"></td>
<td data-bind="text: Location"></td>
</tr>
</tbody>
</table>
Javascript
ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");
var completeEmployeeList = null;
// Class used for saving the field values.
function EmployeeList(name, designation, department, location) {
var self = this;
self.Name = name;
self.Designation = designation;
self.Department = department;
self.Location = location;
}
// View Model - JavaScript that defines the data and behavior of your UI
function EmployeeListViewModel() {
var self = this;
// observableArray equivalent of a regular array,
self.Employees = ko.observableArray([]);
self.AddEmployees = function (name, designation, department, location) {
self.Employees.push(new EmployeeList(name, designation, department, location));
}
}
function MainFunction() {
completeEmployeeList = new EmployeeListViewModel();
// Retrieve the SharePoint list items
retrieveListItems();
// Activates knockout.js
ko.applyBindings(completeEmployeeList);
}
function retrieveListItems() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Documents');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><RowLimit>10</RowLimit></View>");
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var currentItem = listItemEnumerator.get_current();
completeEmployeeList.AddEmployees(currentItem.get_item("Title"), currentItem.get_item("FileRef"), currentItem.get_item("Editor"),currentItem.get_item("File_x0020_Size"), currentItem.get_item("Modified"));
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
This seems to work as I'd expect. If you aren't seeing a clickable link maybe there's something in your css changing the styling?
Here's a repro snippet, but I removed code related to your api calls:
var completeEmployeeList = null;
// Class used for saving the field values.
function EmployeeList(name, designation, department, location) {
var self = this;
self.Name = name;
self.Designation = designation;
self.Department = department;
self.Location = location;
}
// View Model - JavaScript that defines the data and behavior of your UI
function EmployeeListViewModel() {
var self = this;
// observableArray equivalent of a regular array,
self.Employees = ko.observableArray([]);
self.AddEmployees = function(name, designation, department, location) {
self.Employees.push(new EmployeeList(name, designation, department, location));
}
}
function MainFunction() {
completeEmployeeList = new EmployeeListViewModel();
// Retrieve the SharePoint list items
//retrieveListItems();
//test value
completeEmployeeList.AddEmployees('Test Name', 'Test Dept', 'Test Designation', 'Test Location');
// Activates knockout.js
ko.applyBindings(completeEmployeeList);
}
MainFunction()
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tblEmployeeList" border="1">
<thead>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Department</th>
<th>Location</th>
</tr>
</thead>
<!-- Iterating through every list item using foreach of KO -->
<tbody data-bind="foreach: Employees">
<tr>
<td data-bind="text: Name">
<span data-bind="text: Name"></span>
</td>
<td>
</td>
<td data-bind="text: Department"></td>
<td data-bind="text: Location"></td>
</tr>
</tbody>
</table>

row span using MVC5

#if (ViewData["post"] != null)
{
foreach (var item in ViewData["post"] as IEnumerable<Employee.Models.ApplyJob>)
{
<tr>
<td>#item.PerferenceNo</td>
<td>#item.JobName</td>
<td>#item.Location</td>
<td>Action</td>
</tr>
}
}
how to use row span on PerferenceNo and JobName using MVC4>
You need to compare the previous values with the current values, but there is no need to use rowspan (which would unnecessarily complicate it). You can just generate an empty <td> element when the cell matches the previous value.
#{
var data = ViewData["post"] as IEnumerable<Employee.Models.ApplyJob>;
int perferenceNo = 0;
string jobName = "";
}
#foreach (var item in data)
<tr>
#if (item.PerferenceNo == perferenceNo)
{
<td></td>
}
else
{
perferenceNo = item.PerferenceNo;
<td>#item.PerferenceNo</td>
}
... // ditto for JobName
<td>#item.Location</td>
</tr>
}
And I strongly recommend you pass a model to the view, rather than casting it from ViewData
If you do want to use the rowspan attribute, then you code will need to be
#foreach (var item in items)
{
int perferenceNoCount = data.Count(x => x.PerferenceNo == item.PerferenceNo);
int jobNameCount = data.Count(x => x.JobName == item.JobName);
<tr>
#if (item.PerferenceNo != perferenceNo)
{
perferenceNo = item.PerferenceNo;
<td rowspan="#(perferenceNoCount)">#item.ID</td>
}
#if (item.JobName != jobName)
{
jobName = item.JobName;
<td rowspan="#(jobNameCount)">#item.Name</td>
}
<td>#item.Location</td>
</tr>
}
But you really should be using view model in that case with properties for the rowspan values and run your queries in the controller.

Create a new Webshop Parameter

I am very new to hybris e-commerce software and trying to learn with the help of wiki documents provided with it.I am trying to create a new Webshop parameter with three options so I can choose any one of then by HMC. I have changed the items.xml and created a enum and a new attribute in Basestore but on HMC name of new parameter is not proper its taking qualifier name appended with "[" can anyone suggest why it is happening and how to define name of new parameter.
1) myextension-items.xml
<itemtype code="MyType" extends="BaseType">
<attributes>
<attribute qualifier="attr1" type="java.lang.String">
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
2) localization\myextension-locales_en.properties (or other: _fr, _de, etc)
type.MyType.name=My Type name
type.MyType.description=My Type description
type.MyType.attr1.name=Attribute 1 name
type.MyType.attr1.description=Attribute 1 description
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
table {
border: 1px solid black;
}
p {
position: relative;
left: 60px;
}
</style>
</head>
<body>
<h2>Pizzahut</h2>
<div id="container">
<label>Megnevezés</label><br>
<input id='Megnevezes' type="text"><br>
<label>Pizza mérete</label><br>
<select id="pizzameret" name="pizzameret" >
<option>S</option>
<option>L</option>
<option>XL</option>
</select><br>
<label>Egységár</label><br>
<input id='Egysegar' type="number"><br>
<label>Fénykép</label><br>
<input id='fenykep' type="text"><br>
<button onclick="pizzaHozzaad()">Feltöltés</button>
<!--fügvényhívás-->
</div>
<br>
<br>
<br>
<div id="tablaParent">
</div>
<br>
<br>
<br>
<div id="kosarTartalma">
<p>Kosár tartalma</p>
<table>
<thead>
<tr>
<th>id</th>
<th>pizzameret</th>
<th>megnevezes</th>
<th>egysegar</th>
<th>fenykep</th>
</tr>
<!--
<tr>
<th><input id="idSzuro" /></th>
<th>
<select id="pizzameretSzuro">
<option>S</option>
<option>L</option>
<option>XL</option>
</select>
</th>
<th><input id="megnevezesSzuro" /></th>
<th><input id="egysegarSzuro" /></th>
<th><input id="fenykepSzuro" /></th>
</tr>
-->
</thead>
<tbody id="kosarBody">
</tbody>
</table>
</div>
<script type="text/javascript" , src="pizza.js"></script>
<script type="text/javascript" , src="webshoplogika.js"></script>
</body>
</html>
function Pizza(id,megnevezes,egysegar,fenykep,pizzameret)
{
this.id=id;
this.pizzameret=pizzameret;
this.megnevezes = megnevezes;
this.egysegar = egysegar;
this.fenykep = fenykep ;
}
"use strict"
var termekek = [];
var tablazatParent = "";
var kosar = [];
var novekvo = true;
termekek.push(new Pizza(1, "pizza1", 600, "kamu.jpg","xl"));
termekek.push(new Pizza(2, "pizza2", 100, "kamu.jpg","xl"));
termekek.push(new Pizza(3, "pizza3", 200, "kamu.jpg","xl"));
termekek.push(new Pizza(4, "pizza4", 4000, "kamu.jpg","xl"));
termekek.push(new Pizza(5, "pizza5", 5000, "kamu.jpg","xl"));
termekek.push(new Pizza(6, "pizza5", 12000, "kamu.jpg","xl"));
var pizzameret = document.getElementById("pizzameret");
var Megnevezes = document.getElementById("Megnevezes");
var Egysegar = document.getElementById("Egysegar");
var fenykep = document.getElementById("fenykep");
var id = 6;
window.addEventListener('load', Window_Load_Handler, false);
function Window_Load_Handler() {
tablazatParent=document.getElementById("tablaParent");
tablazatRajzoloFuggveny(termekek);
}
function pizzaHozzaad() {
id++;
var pizzaNev = Megnevezes.value;
var pizzaAr = Egysegar.value;
var fenykepURL = fenykep.value;
var ujPizza = new Pizza(id, pizzaNev, pizzaAr, fenykepURL);
termekek.push(ujPizza);
console.log(ujPizza);
tablazatFrissites();
}
function tablazatRajzoloFuggveny(inputArray) { /* ugy kell meghivni, masik gombnyomasra,hogy at kell adnunk neki paratmeterkent egy tombot,
amivel megmondjuk melyik tombbol szeretnenk tablazatot csinalni */
var tablazat = document.createElement('table')
tablazat.setAttribute("border", "true"); /* a tablazatot hozza letre */
var sor = document.createElement('TR'); /* a sort hozza letre */
for (var k in inputArray[0]) {
var cella = document.createElement('TH') /*create elementtel keszitettunk egy header cellat */
cella.innerText = k;
cella.addEventListener('click', rendezd , false);
sor.appendChild(cella); /* cellat felakasztja a sorra */
}
var btnCella = document.createElement('TH'); // gombot kreálunk
btnCella.innerText = "Kosárba";
sor.appendChild(btnCella);
tablazat.appendChild(sor);
var btnCella = document.createElement('TH'); // gombot kreálunk
btnCella.innerText = "Törlés";
sor.appendChild(btnCella);
tablazat.appendChild(sor);
var sor = document.createElement('TR');
for (var k in inputArray[0]) {
var cella = document.createElement('TH') /*create elementtel keszitettunk egy header cellat */
if (k == "pizzameret") {
var szuro = document.createElement('SELECT');
szuro.id= k
var optionXL = document.createElement('OPTION')
optionXL.text = 'XL'
optionXL.value = 'XL'
var optionL = document.createElement('OPTION')
optionL.text = 'L'
optionL.value = 'L'
var optionS = document.createElement('OPTION')
optionS.text = 'S'
optionS.value = 'S'
szuro.appendChild(optionXL)
szuro.appendChild(optionL)
szuro.appendChild(optionS)
szuro.addEventListener('change', szurd , true);
cella.appendChild(szuro)
} else {
var szuro = document.createElement('INPUT');
szuro.id= k
szuro.addEventListener('focusout', szurd , true);
cella.appendChild(szuro)
}
sor.appendChild(cella); /* cellat felakasztja a sorra */
}
tablazat.appendChild(sor); /* sort felakasztja a tablara */
document.body.appendChild(tablazat);
for (var i = 0; i < inputArray.length; i++) {
var sor = document.createElement('TR'); /* a sort hozza letre */
for (var k in inputArray[i]) {
var cella = document.createElement('TD') /*create elementtel keszitettunk egy header cellat */
cella.innerText = inputArray[i][k]; /*aktualis auto k kulcsai, value-jat olvassa be */
sor.appendChild(cella);
}
var btnCella = document.createElement('TD'); // gombot kreálunk
btnCella.innerHTML = "";
sor.appendChild(btnCella);
tablazat.appendChild(sor);
tablazat.appendChild(sor);
var kosarbaBtn = document.createElement('input');
kosarbaBtn.setAttribute('type', 'button');
kosarbaBtn.setAttribute('value', 'Kosárba');
kosarbaBtn.setAttribute('termekID',inputArray[i].id );
kosarbaBtn.addEventListener('click', Kosarba_Click_Handler , false);
var torolBtn = document.createElement('input');
torolBtn.setAttribute('type', 'button');
torolBtn.setAttribute('value', 'Torlés');
torolBtn.setAttribute('termekID',inputArray[i].id );
torolBtn.addEventListener('click', toroldasort , false);
btnCella.appendChild( kosarbaBtn);
var btnCella = document.createElement('TD'); // gombot kreálunk
btnCella.appendChild( torolBtn);
sor.appendChild(btnCella);
tablazat.appendChild(sor);
tablazat.appendChild(sor);
}
tablazatParent.appendChild(tablazat);
}
function toroldasort(){
var btn = event.target;
var id = btn.getAttribute('termekID');
console.log("termek id:" + btn.getAttribute('termekID'));
for( var i = 0; i < termekek.length; i++){
if ( termekek[i].id == id ) {
console.log("lofasz");
termekek.splice(i, 1);
break;
}
}
tablazatFrissites();
}
function tablazatFrissites() {
//var tablazatParent=getElementById('tablazat'); //feltetteük a tetejére
var nodeTermekLista = document.querySelector('#tablaParent');
nodeTermekLista.innerText='';
tablazatRajzoloFuggveny(termekek);
}
function rendezd() {
var header = event.target
var attr = header.innerText
console.log(attr); // ha igy mukodik akkor nem is kell gomb se input type legyen stb. próba cseresznye
// fasza, megy, akkor folytassuk, ugye rendezni kell a szerint az attributum szerint amit megnyomtunk
// ez most csökkenő sorrendbe rendezi az oszlopokat (már amennyi értelme van ennek stringek esetében)
termekek.sort(function(a, b){
//console.log(a[attr])
// na mindegy, eddigiek alapján a ciklussal láttuk h kell kiszedni egy ojjektum mezejét
// á faszom, kell erre legyen vmi egyszerű megoldás
console.log(a[attr] +' '+ b[attr])
// ez ugye számokra jó de stringekre nem
if (novekvo) {
if (a[attr] < b[attr])
return -1;
if (a[attr] > b[attr])
return 1;
} else {
if (a[attr] < b[attr])
return 1;
if (a[attr] > b[attr])
return -1;
}
return 0;
})
novekvo = !novekvo
console.log(novekvo)
// https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value
// fasza, műxik, látszik a termékeken h most csökkenő sorrendben vannak
// ja igen és még ki kell rajzolni
tablazatFrissites()
}
function szurd() {
var szurtTermekek = []
var asd = event.target
console.log(termekek)
for (var i = 0; i < termekek.length; i++) {
console.log(termekek[i][asd.id]+' '+asd.value)
if (termekek[i][asd.id] == asd.value) {
console.log(termekek[i][asd.id])
szurtTermekek.push(termekek[i])
}
}
console.log(szurtTermekek)
if (szurtTermekek.length > 0) {
var nodeTermekLista = document.querySelector('#tablaParent');
nodeTermekLista.innerText='';
tablazatRajzoloFuggveny(szurtTermekek)
}
}
function Kosarba_Click_Handler() {
var btn = event.target;
var id = btn.getAttribute('termekID');
console.log("kosarba termek id:" + btn.getAttribute('termekID'));
var valasztottTermek;
for( var i = 0; i < termekek.length; i++){
if ( termekek[i].id == id ) {
valasztottTermek = termekek[i];
console.log("kosarba!!");
break;
}
}
var kosarLista = document.querySelector('#kosarBody');
var sor = document.createElement('TR');
for (var k in valasztottTermek) {
var cella = document.createElement('TD')
cella.innerText = valasztottTermek[k];
sor.appendChild(cella);
}
kosarLista.appendChild(sor);
}

Resources