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
}
Related
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!
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.
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.
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
i am taking help of this example: http://mleibman.github.com/SlickGrid/examples/example-checkbox-row-select.html and add a checkbox column to my grid and assign unique_id value of my record to the id of checkbox column i am getting checked columns number using grid.getSelectedRows();
it gives me a index number of row. how can i get id of this selected rows in slickgrid? please help me if anyone have any idea.
var selectedrows = grid.getSelectedRows();
for(i=0;i<len;i++){
var d = grid.getData().getItem(selectedrows[i]);
if(d != null && d != 'undefined'){
dataView.deleteItem(d.id);
grid.invalidate();
grid.updateRowCount();
grid.render();
}
}
It removes rows from grid. not from server side.