Selecting children nodes - dom

How can I select the following element in order to insert a new element?
NOTE: Assume valid <tr> and <td> for the nested tables and inserting the <pre> tag.
<html>
<body>
<table>
<tbody>
....more elements here...
<table>
<tbody> <----- how do I select this?
</tbody>
</table>
</tbody>
</table>
<body>
</html>
The following select isn't working?
// This isn't selecting the node correctly?
Element tablebody = doc.body().select("table > tbody > table > tbody").first();
Element pre = tablebody.appendElement("pre");
pre.text("hello");

That is not valid markup. A table cannot exist directly inside a tbody.
If your inner table isn't in a tr > td, then that inner table is actually being constructed as a next sibling of the outer table. In other words, you don't actually have an inner table at all.
Unless the markup can be corrected, you have to treat that "inner table" as a following sibling:
Element tablebody = doc.body().select("table + table > tbody").first();
If you can correct the markup, you can either complete the selector with the missing tr and td bits:
Element tablebody = doc.body().select("table > tbody > tr > td > table > tbody").first();
Or simply replace one of the child selectors with a descendant selector:
Element tablebody = doc.body().select("table > tbody table > tbody").first();
Additionally, a tbody can only have tr elements as children. You cannot append a pre element inside a tbody the way you're trying to do. You probably want to select the first tr > td in that tbody and append it there.

Related

Getting text from one of the columns from a grid

I have a grid table having many columns and I have to get the text of values of 1st column. The grid table structure is shown below
There is a class for a complete row and then inside this class and each column cell has the same class
<div row-index= 'row1'>
<div col-id= 'datecolumn2' /div>
<div col-id= Name1 /div>
<div col-id= city1 /div>
/div>
<div row-index= 'row2'>
<div col-id= datecolumn2 /div>
<div col-id= Name2 /div>
<div col-id= city2 /div>
/div>
like this, there are around 1000 rows. I have to traverse through each row and get the text of only date column values
Expected: I should get the text of date column class in an array
If I understand correctly, you want to iterate through each row and get the value for datecolumn. From your code I see the class name for row and column are shown as they are not same classname. But I assume they are same. It would be more helpfull if you can copy the code from your source. Anyhow with minimal information, I have following code that works to read though the dateColumn from each row and outputs the data in that column.
const datecolumns = element.all(by.css("div.row .datecolumn"));
//If there is another child tag below datecolumn and the text is in that tag then you need to include that class in the above element finder
datecolumns.map(function (eachDateColumn, index) {
eachDateColumn.getText().then(function (dateValue) {
console.log("Date value in column " + index + " is " + dateValue)
})
})
More straight way:
const datecolumns = element.all(by.css("div.row .datecolumn")).getText();
It is exactly 1000 rows? do they start at <div class = 'row1'> and end in <div class = 'row1000'>?
If that's the case, the element locator itself should be:
element(by.css('.row1 .datecolumn2'));
Then if you're looping through all the rows, just change it like this:
for (i= 1; i < rows.length; i++) {
element(by.css('.row' + i + '.datecolumn2')).getText();
// here you do whatever you need to do with the text
}

Full text search not working completely on rails 4 PG 9.3

I have a problem with search on PG. I have a table with two columns first name and last name. I want someone to be able to search for one person using their first name, their last name, or the full name.
I was following the Railscast #343 on full text search for PG and for what I understand, the search is supposed to work as I intend it to work but it doesn't. The code below will only return results when you put the exact first name or last name; it will not return anything is you put the first name and last name or if you only put a part of the first name or last name.
I would appreciate any input on how to make this work as I intend.
Model
def self.text_search(query)
if query.present?
where("first_name ## :q or last_name ## :q", q: query)
else
where(nil)
end
end
Controller
def index
#members = #organization.members.text_search(params[:query]).page(params[:page]).per(20)
end
Console Output
SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "members" WHERE "members"."organization_id" = $1 AND (first_name ## 'jon' or last_name ## 'jon') AND (expiration_date <= '2014-11-30') AND (expiration_date > '2014-10-31') LIMIT 20 OFFSET 0)
Just a couple ideas on what might help get you what you are looking for.
First, on your query, I believe you should be using ILIKE to make the search case insensitive and also a %% wrap around your search term so that postgres knows to do a partial match. Here's an example from an autocomplete jquery text box I use. Link to the PG Documentation
def users
search_term = params[:term]
#users = current_account.users.where("name ILIKE ?", "%#{search_term}%").order(name: :asc)
respond_to do |format|
format.json { #users }
end
end
The second suggestion I would make would be to use Ransack so that you can search multiple fields at once with the same search box. For example, if you were using Ransack you could do something like the following: Link to Ransack on Github
<%= search_form_for #q do |f| %>
<%= f.label :first_name_or_last_name %>
<%= f.search_field :first_name_or_last_name %>
<%= f.submit %>
<% end %>
and then your controller would be as simple as:
def index
#q = Member.search(params[:q])
#members = #q.result(distinct: true)
end
To search for full name as well as first and last, I think you would have to create a field in your model called full_name and then you could easily add it to the search. I'm not sure how else you could do it without it actually being in the model.
Hope that helps!

insert empty date on unitils dataset

I got error similar to this: Unitils dataset - insert into sybase datetime column
My case is that need to insert a date value that is empty. Empty String does not do the thing. Can anyone help me?
If you leave your date element off of the row definition, it won't add anything in that field. So with a table definition of:
CREATE TABLE Table (
id INTEGER,
name VARCHAR,
birthDate DATE
);
create a row like this:
<table id="3" name="Katie"/>
<table id="4" name="Christie" birthDate="2001-04-22"/>
to load an empty date in ID 3.

How to select a row in kendogrid after filtering

I have a kendogrid. What I do is first filter it, which works fine.
After having it filtered, I want to select a specific row. I am sure I have the row in the result of the filter.
Example:
data = id=a1, id=a2, id=a3, id=a4, id=a5, id=a6
filter result:
id=a2, id=a4, id=a6
I would like to select the row a4.
First of all loop through the Grid's data which is currently displayed (i.e.
var arrayOfModels = $('#GridName').data().kendoGrid.dataSource.view();
next add the k-state-selected class to the row you want to make it selected
$('#GridName tbody [data-uid='+model.uid+']').addClass('.k-state-selected')
where model is the record from the arrayOfModels above which you need

How to easily create tables in the template toolkit View in perl/Catalyst

I am developing an App using Perl's Catalyst framework.
In trying to keep presentation logic out of my models I am looking for a way in the VIEW (template toolkit) to generate an HTML table from a given data structure.
I currently use HTML::Table::FromDatabase to generate my html tables from SQL queries
but this is currently in the Model. I am looking to isolate presentation logic to the View rather than have it in the model .
Any advice on this would be helpful
This is from memory and just riffing so consider it untested. It’s a simple way to automatically iterate through columns and records.
Assumes a sub something like this with a DBIx::Class based model–
sub some_action : Local Args(0) {
my ( $self, $c ) = #_;
my $rs = $c->model("SomeTable")->search({},{rows => 10});
$c->stash( some_rs => $rs );
}
And then the matching template–
[% records = some_rs.all %]
[% RETURN UNLESS records.size %]
[% columns = records.0.columns %]
<table>
<tr>
[% FOR column IN columns %]
<th>[% column | ucfirst | html %]</th>
[% END %]
</tr>
[% FOR item IN records %]
<tr>
[% FOR column IN columns %]
<td>[% item.${column} | html %]</td>
[% END %]
</tr>
[% END %]
</table>
I pass the data structure (as an array of hashes) into TT and just use TT logic to build the table, with CSS classes to control the look of the table.
Simplified example of the template:
<table class="ixTable">
[% FOREACH listing = listings %]
<tr class="ixRow">
<td class="ixAddress">[% listing.address %]</a></td>
<td class="ixPrice">[% listing.listprice %]</td>
<td class="ixSqFt">[% listing.sqft %]</td>
</tr>
[% END %]
</table>
Good ol' CGI.pm makes this not too difficult, but to get any real help you are going to have to show what your data structure looks like.
One potential issue is that your data may be in hashes that by their nature don't provide a column order (though database purists will tell you HTML::Table::FromDatabase is wicked and bad for encouraging select * and assuming column order is meaningful).
HTML::Table::FromDatabase itself uses HTML::Table; you might see if that meets your needs.