does someone knows how to grab the text from the first td and not the next? And make it 0 if it doesn't have a value:
<tr>
<td style="width:28%;">
2 plantas··
</td>
<td style="width:28%;">
300m² terreno
</td>
</tr>
In the picture above, my code (below) is also grabbing the next td which is a blank space, but I want to grab the one that says "300m2 terreno":
terreno=tree.xpath('//td[contains(text(),"planta")]/following-sibling::td/text()')
terreno2=[item.strip() for item in terreno]
terreno3=[]
for casa in terreno2:
if len(casa)<1: continue
terreno3.append(float(casa.split('m²')[0]))
And I'm getiing for output this:
['300m² terreno', '', '', '', '', '', '315m² terreno', '', '', '', '', ''....]
Here is the link from my source:
https://www.avisosdeocasion.com/Resultados-Inmuebles.aspx?n=venta-casas-nuevo-leon&PlazaBusqueda=2&Plaza=2
Using this xpath :
//td[contains(text(),"planta")]/following-sibling::td[1]/text()
# ^
limit to the fisrt 'td'
Related
I am trying to implement a feature where a user would be able to add new columns and rows to a table using vue js. I am able to push a tag to the table however the method I'm using to add the I don't think its the right way especially since the td's are being added to the object but only to the view itself.
I am pulling the default html table content from laravel's helper file
(object)array(
'label' => 'Table',
'field_name' => '',
'type' => 'table',
'properties' => (object)array(
'headers' => [
'Header 1',
],
'rows' => [
(object) array(
'value' => 'Row 1 content',
),
],
)
)
Html(vue js)
...
<div v-if="field.type == 'table'">
<pre>{{field.properties.headers}}</pre><br>
<pre>{{field.properties.rows}}</pre>
<table :class="`table ` + field.properties.style" :id="`table`+index">
<thead>
<tr>
<th v-for="(header, index) in field.properties.headers" v-if="header.length > 0">
{{header}}
<i class="fa fa-trash"></i>
</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in field.properties.rows" :key="index" id="default-row">
<td>{{row.value}}</td>
</tr>
</tbody>
</table>
<table>
<tr>
<td>
Add Column
Add Row
</td>
<td></td>
<td></td>
</tr>
</table>
</div>
...
Script(vue js)
...
methods: {
addTableColumn(properties, index) {
properties.headers.push('Column Heading');
$(`#table${index} #default-row`).append(`<td>Row Content</td>`);
},
removeTableColumn(properties, index) {
properties.headers.splice(index, 1);
properties.rows.splice(index, 1);
},
addTableRow(properties, index) {
// let columnCount = properties.headers.length;
// for(let i = 0; i < columnCount; i++) {
// properties.rows.push({'value': 'Row content'});
// }
// console.log(columnCount);
// console.log(index);
// rows.push({ 'value': 'Row column' });
$(`#table${index}`).append(`<tr>${$('#default-row').html()}</tr>`);
}
},...
View
As seen in the picture below, I clicked the "add column" button and only the heading itself is pushed to the array and not the new td content(Row content).
I am using sweetalert in MVC project, and rendering checkbox in to sweetalert using CheckBoxFor html helper.
But when I clicked on these checkboxes, sometime it is getting clicked and sometime it is not getting clicked. I am not getting the reason behind this weird behaiviour.
And at the same place I tried adding normal html checkboxes, these checkboxes are working perfectly fine.
Can anyone help to know the reason behind this weird behaiviour ?
Code:
View:
<table class="table">
#foreach (var item in Model)
{
<tr>
<td>
<input type="checkbox" name="Asha" style = "display:block;height:20px;width:20px;"/>
</td>
<td style="padding-left:20%">
#Html.CheckBoxFor(modelItem => item.Status,htmlAttributes: new { style = "display:block;height:20px;width:20px;", id = item.Id ,Class = "process-to-lock", value = item.Name})
</td>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</table>
SweetAlert:
$("#unLockNominations").click(function (e) {
showCustomLoader();
$.ajax({
type: 'GET',
url: '#Url.Action("UnlockNomination", "Review")',
dataType: 'html',
success: function (result) {
hideCustomLoader();
swal({
title: "Awards to unlock",
html: true,
text: result,
showConfirmButton: ($(result).filter('#no-awards').text() == undefined || $(result).filter('#no-awards').text() == ""),
confirmButtonColor: "#0070b9",
confirmButtonText: "Submit",
showCancelButton: true,
cancelButtonText: "Cancel",
closeOnConfirm: false,
closeOnCancel: true
}
}
Here in above code text renderd in sweet alert is a html table which I mentioned above.
I want to add an id to the "tr" elements of the mvccontrib grid I build:
<tr id="0"/>
<tr id="1"/>
so if the table contains 10 rows, the ids are 0 through to 9.
One way is to add an additional item to my entity to store this value and then create this as a hidden column with the id as the value of this item - not very elegant.
Is there a more elegant way to do this?
Thanks
I've got this far but now it complains at the RenderUsing line, any ideas?
#model IEnumerable<Tens.Models.UserPreviousNamesView>
<div class="demo_jui">
#{
var userId = 0;
foreach (var item in Model)
{
userId = item.Id;
break;
}
#(Html.Grid(Model.Select((item,index) => new { Item = item, Index = index}))
.Columns(col =>
{
col.For(p => p.Item.Title);
col.For(p => p.Item.Name);
col.Custom(#<text>
#Ajax.ActionLink("Delete", "DeleteUserPreviousName", "Summary", null, null, new { id = item.Item.Id, #class = "deleteUserPreviousName" })
</text>).Encode(false);
})
.RowAttributes(p => new Hash(Id => "id"+p.Item.Index.ToString()))
.Attributes(Id => "userPreviousNamesTable")
.Empty("You currently have no Previous Names.")
.RenderUsing(new Tens.GridRenderers.UserPreviousNamesGridRenderer<Tens.Models.UserPreviousNamesView>()));
}
You could transform the model to add it a row index and then use the RowAttributes method:
#model IEnumerable<MyViewModel>
#(Html
.Grid(Model.Select((item, index) => new { Item = item, Index = index }))
.Columns(column =>
{
column.For(x => x.Item.Foo);
column.For(x => x.Item.Bar);
})
.RowAttributes(x => new Hash(id => string.Format("id{0}", x.Item.Index)))
)
Also I have pre-pended the id with the id keyword as ids in HTML cannot statr with a number as shown in your example.
Sample output:
<table class="grid">
<thead>
<tr>
<th>Foo</th>
<th>Bar</th>
</tr>
</thead>
<tbody>
<tr id="id0" class="gridrow">
<td>foo 1</td>
<td>bar 1</td>
</tr>
<tr id="id1" class="gridrow_alternate">
<td>foo 2</td>
<td>bar 2</td>
</tr>
<tr id="id2" class="gridrow">
<td>foo 3</td>
<td>bar 3</td>
</tr>
</tbody>
</table>
You can always show hide columns without adding id to particular row or columns like below
$(".mvcGridDollarHeader th:nth-child(16)").hide();
$(".mvcGrid td:nth-child(16)").hide();
Where mvcGrid is tableStyle and mvcGridDollarHeader is header style.
#grid1.GetHtml(
tableStyle: "mvcGrid",
displayHeader: true,
emptyRowCellValue: "",
headerStyle: "mvcGridDollarHeader",
Just a quick question from a newbie to the pro's.
I am trying to implement a editable grid type form in my application. Here is the example.
#for (int i = 0; i < Model.Items.Count; i++)
{
<tr>
<td>#Html.CheckBoxFor(m => m.Items[i].fav_ind)
</td>
<td>
<a href="#" onclick="ShowDeals(#Model.Items[i].item_no);event.returnValue = false; return false;">
DEALS</a>
</td>
<td>#Html.DisplayFor(m => m.Items[i].item_no)
</td>
<td>#Html.DisplayFor(m => m.Items[i].item_desc)
</td>
<td>#Html.DisplayFor(m => m.Items[i].mfr_item)
</td>
<td>#Html.DisplayFor(m => m.Items[i].pack_size)
</td>
<td>#Html.DisplayFor(m => m.Items[i].purc_uom)
</td>
<td>#Html.DisplayFor(m => m.Items[i].purc_uom_conv)
</td>
<td>#Html.DisplayFor(m => m.Items[i].list_prc)
</td>
<td>
#Html.TextBoxFor(m => m.Items[i].nett_prc)
</td>
<td>
#Html.TextBoxFor(m => m.Items[i].Qty)
</td>
</tr>
}
This #for is inside a Html.BeginForm, because I want the user to be able to edit the last 2 fields (nett_prc and qty. There is also a submit bottom on the bottom of this grid(table).
Now for the question, when I submit, I get all the rows back in the controller, but on the items only the 2 fields where is is Html.TextBoxFor() has data in it. I want to get all the fields in the controller. I kwno I can use #Html.HiddenFor(), but I want to be able to display the other fields in labels, and when the user submits I want the values ass well.
Thanks in advance.
You can do both DisplayFor and HiddenFor at the same time:
<td>
#Html.DisplayFor(m => m.Items[i].item_no)
#Html.HiddenFor(m => m.Items[i].item_no)
</td>
However, why would you need HiddenFor? If the user is not supposed to edit some of the values, you can't trust the values that come from the form anyway. And if you can't trust them you will have to read the originals (e.g. from a database). What does HiddenFor buy you here?
For the Table class in user guide, it mention how to generate a table with multiple columns/rows. But I want to ask how can we generate a table that contain multiple sub-table, example as below:
<table>
<tr>
<td>
<table>
<tr>
<td>sub-table-01</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>sub-table-02</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>sub-table-n</td>
</tr>
</table>
</td>
</tr>
</table>
Could anyone suggest the snippet for this function?
Thanks
You can nest the calls to generate(). Example:
$data1 = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9),
);
$data2 = array(
array('a', 'b'),
array('c', 'd'),
array('e', 'f'),
);
$data3 = array(
array('Heading1', 'Heading 2', 'Heading 3'),
array('Row1', $this->table->generate($data1), $this->table->generate($data2)),
array('Row2', $this->table->generate($data1), $this->table->generate($data2)),
array('Row3', $this->table->generate($data1), $this->table->generate($data2)),
);
echo $this->table->generate($data3);
You'll have to replace this with your own data in a way that makes sense of course, but hopefully this gives you the idea.