Updating Table dynamically - Ajax HTML - html

I am trying to update the table as new records come in for table below:
I have got the part where I need to get live information using Ajax. I am using the <tr id = {$university}> as ids to create new rows or update existing. But the updating doesn't seem to work. i.e. If a new student entry is made for University A, than adding a new HTML code. So my existing HTML code looks like
<tr id = "A">
<td>A</td>
<td>Mr. X</td>
<td>a#b.com</td>
</tr>
<tr id = "A">
<td></td>
<td>Mr. Y</td>
<td>e#f.com</td>
</tr>
<tr id = "A">
<td></td>
<td>Mr. S</td>
<td>u#i.com</td>
</tr>
and when I add new data using same <tr id = "A">, it does not append information, but creates a new row:
<tr id = "A">
<td>A</td>
<td>Mr. Z</td>
<td>t#t.com</td>
</tr>
will not append information but create another row in UI. How can I append new information to existing rows?
Added the js code: http://pastebin.com/4tjyUgZa

IDs in HTML are meant to be unique, you shouldn't be duplicating them. Try using a class instead, like <tr class="a">.
I also think you need to revisit your table structure. It looks like what you need are multiple tables, such as table "a" and table "b" that you can then append rows to. The way you are manipulating the table rows just isn't how they're built to work. If you had something like <table id="a"> and <table id="b"> you could then simply target those and add rows easily.
You may also want to make use of a JavaScript framework such as jQuery. It will make manipulating the table much easier and you will be able to write the code much faster.

Related

Creating a dynamic table In HTML and AngularJS from contents of a Javascript array

I need help creating a dynamic table in the format of a round robin competition using HTML and AngularJS. An array of strings will be given and then the table will be created based on how many names were in the list so part of the table will be generated dynamically and part of the table will always be the same. This is an example of a table that would be generated if I passed an array with 8 names. Only columns A, B, and C should have any information when the table is generated though I kept everything blank for simplicity's sake. The rest of the boxes should all be text input fields.
Until now most of the tables I have done have been pretty simple and I am a little out of my depth here, any help would be much appreciated.
Assuming you always have a full 8 teams this would get you started
<table>
<tr>
<th>club</th>
<th>team</th>
<th>#</th>
<th ng-repeat="item in items">{{$index+1}}</th>
<th>V</th>
<th>TS</th>
</tr>
<tr ng-repeat="item in items">
<td>{{item.club}}</td>
<td>{{item.team}}</td>
<td>{{item.rank}}</td>
<td ng-repeat="item in items" ng-class="{black:$index==$parent.$index}"></td>
<td><input ng-model="item.v"></td>
<td><input ng-model="item.ts"></td>
</tr>
</table>
DEMO
This is a really nice example of using nested ng-repeat elements.
Please see this plunker for a working demo.
The main trick for detecting when to black out a box is to use ng-init="$rowIndex=$index" on the outer ng-repeat (where we generate a row for each entry). This allows the inner ng-repeat (where we generate a column for each entry) to have an ng-class="{'blackout': $index==$rowIndex}"

To create xpath for html table to access desired record using 3 inputs

This is a structure of very basic html table. I want to create xpath for following scenario.
I will insert 2 field names like 'Name' and 'Salary' along with value of 'Name' field (say for example 'STU') then output should be 25k.
I was given hint like
string (xpath which will have 2 field names and one value) output of this function will be that key.
<html>
<body>
<h3>MY TABLE</h3>
<table>
<tbody>
<tr>
<th>id</th>
<th>Name</th>
<th>date</th>
<th>Address</th>
<th>salary</th>
</tr>
<tr>
<td>XYZ</td>
<td>STU</td>
<td>12/20/2015</td>
<td>Mumbai</td>
<td>25k</td>
</tr>
<tr><td>PQR</td>
<td>ABC</td>
<td>01/05/2015</td>
<td>Chennai</td>
<td>25k</td>
</tr>
<tr>
<td>ABC</td>
<td>PQR</td>
<td>03/09/2015</td>
<td>Bangalore</td>
<td>20k</td>
</tr>
<tr>
<td>emp4</td>
<td>XYZ</td>
<td>08/12/2015</td>
<td>Delhi</td>
<td>30k</td>
</tr>
</tbody>
</table>
</body>
</html>
Basics:
The first thing you will need to do is find which column(s) in the table contain(s) the field(s) you are searching for.
For example, to find the position of the Name column:
count(//tbody/tr/th[./text() = 'Name']/preceding-sibling::th) + 1
The above will return 2. (Of course, this technique won't necessarily work well if there are colspan attributes used in the HTML, but there are none in your example.)
Then, you can find the rows that contain a specific value in this column - for example STU - in this column like this:
//tbody/tr/td[position() = $WherePosition][./text() = 'STU']/..
Notice the use of the variable $WherePosition above. Here, I have used it to represent the result of the previous query (1). Depending on what tool you are using to perform the XPath query, you may or may not have the option to set variables. If you wish to use a single XPath expression or you don't want to or can't use variables, you can simply replace it with the previous XPath expression, although it will become less readable.
It's worth noting that aside from readability, variables will also make it easier to re-use the same expression, because you can, for example, substitute 'Name' in the first query for $WhereField, if you tell the XPath evaluator that you want to set the $WhereField variable to Name. And in the query to find the specific row (2), you can substitute 'STU' for $WhereValue, if you also set this variable accordingly.
Apply it:
Now to get the position of the salary column. If you used my tip above about using variables, you could re-execute the same expression as (1) again, but with the $WhereField variable set to salary instead of Name. i.e. count(//tbody/tr/th[./text() = $WhereField]/preceding-sibling::th) + 1
And if you stored the result of query (2) as a variable called $matching_rows and the salary column position as $SalaryPosition, then to return the salary for the row where Name = STU, you could simply finish with: $matching_rows/td[position() = $SalaryPosition]/text(), and you would get the answer 25k.
TL;DR
In summary, as an XPath 1.0 one-liner to get the salary for the row with Name = STU:
//tbody/tr/td[position() = count(//tbody/tr/th[./text() = 'Name']/preceding-sibling::th) + 1][./text() = 'STU']/../td[position() = count(//tbody/tr/th[./text() = 'salary']/preceding-sibling::th) + 1]/text()

How can I support rule definition from a user for my business logic processing?

I have a case where I have an existing method that does a specific kind of processing. I have setup a database table that it checks and if a specific value in a column exists it uses the value in one of the columns.
Example: let's say that I have a method that charges a user. And I have in the table a row that has a column for the country and a column for reduction percentage. So while I am processing the user if the user's country exists in the table I use the value of the column to reduce the price. So far so good.
My question is how could I enhance my design in order to add more general/complex rules?
E.g. I would like to support some kind of interface that the user specifies rules e.g. a user's age or a product weight etc and based on this rules my code processing can figure out how to apply them?
I mean how could I extend my simple table and business logic processing with the country/percentage values to a small rule based setup?
I don't need really complex rules. Just the ability to be let the define a rule if needed
You have to support a certain set of operators, as well as possible fields to be checked against the rule and certain events when the rule is fullfilled.
I would suggest something like this: jsFiddle
<table>
<tr>
<td>Field</td>
<td>
<select><option>Country</option><option>Age</option></select>
</td>
</tr>
<tr>
<td>Operator</td>
<td><select><option>greater than</option><option>smaller than</option><option>not empty</option></select>
</td>
</tr>
<tr>
<td>Value</td>
<td><input id="value" type="text" /></td>
</tr>
<tr>
<td>action</td>
<td><select><option>10% discount</option><option>other stuff</option><option>other stuff 2</option></select></td>
</tr>
</table>
That's just a very quick example of how it could look. You can add any operators and actions you want. You could also include a target field for example. But what's actually in the dropdowns depends on your requirements.

Parameters and Loops in snippets

I would like to make a snippet that makes an HTML table.
Here are some examples of things to type :
table name address city
- table team wins losses draws
- table views clicks clickthrough
This is what I want it to output : a table with a columns for each of the fields (with 'table' triggering the snippet).
I'd also like to run these field names through a function to transform them (for example to field names - "First Name" -> 'first_name'.
Is this possible? How would I do it?
Not exactly what you want, but I would go with Emmet (here is a handy cheet sheet). There is a Sublime package available, so it's easy to install. It might be a little overwhelming at first, but once you start to use it, you will get the hang of it and it will speed up your html/css production.
Type table>tr*3>th and hit tab at the end. This will produce:
<table>
<tr>
<th></th>
</tr>
<tr>
<th></th>
</tr>
<tr>
<th></th>
</tr>
</table>
Then you can tab to the ths to type in your column headers.

Timeline getting data from database

Timeglider is a timeline project.
Timeglider is a jQuery plugin for displaying any number of events in a highly-flexible timeline.
One of the easiest way for fetching and reading data is using a TABLE.
this TABLE is a HTML TABLE that have a specific properties
for example we should create table with its data in SQL.
I use the objects like GRIDVIEW or (TABLE and panel) but these are not have those tags.
please help me
may i use json datasource? but i dont know how?
but with table it is easier.
Timeglider timelines can load directly from data you provide in an
HTML table.
may i use with response.write ? or another proposed way?
or add hese line to table. (i know only gridview have property header) but table doesnt??!!!!
please help me.
<!-- The first row of the table is reserved for meta-data.
Class values below are *critical* for mapping out data from the
<td> elements that follow --- though order is not important.
The text in <td> elements is *not* critical: just the class names.
-->
<tr>
<th class="tg-startdate">start date</th>
<th class="tg-enddate">end date</th>
<th class="tg-title">title</th>
<th class="tg-description">description</th>
<th class="tg-icon">icon</th>
<th class="tg-importance">importance</th>
<th class="tg-link">link</th>
</tr>
i solve it by creating my desired HTML code and with
Response.Write();
fire it in the output
and Timeglider is also work good