I am generating a html table dynamically and after that using datatable 1.9.4 plugin to enhance my html table's features. My table looks like below
the "x" are checkboxes, I am trying to select checkboxes with respect to a particular row and column combination. I have values in pairs like (row1,col3) then I need to select that particular cell. I tried reading checkbox text from header row and selecting corresponding checkbox but no luck.
How should I proceed with this. I know there are some methods from dataTable but not very well aware of those.
You lack to tell how exactly you generate those checkboxes. So the following is just how what I would do it. There isnt really difference if the checkboxes is inside a dataTable or anything else.
Example of creating a lot of checkboxes inside a dataTable, all with unique ID's :
for (var row=1;row<=10;row++) {
dataTable.fnAddData([
'<input type="checkbox" id="check_'+row+'_1">',
'<input type="checkbox" id="check_'+row+'_2">',
'<input type="checkbox" id="check_'+row+'_3">',
'<input type="checkbox" id="check_'+row+'_4">',
]);
}
A shorthand function for retrieving the right checkbox, based on row, col pairs :
function dtCheckBox(row, col) {
return document.getElementById('check_'+row+'_'+col);
}
Some examples to show the concept is working :
//setter examples, check 20 random checkboxes
for (var i=0;i<20;i++) {
var row=Math.floor(Math.random()*10)+1,
col=Math.floor(Math.random()*4)+1;
dtCheckBox(row, col).checked=true;
}
//getter example, console out the checked status of all checkboxes
for (col=1;col<=4;col++) {
for (row=1;row<=10;row++) {
console.log(dtCheckBox(row, col).checked);
}
}
See the above in action in this fiddle -> http://jsfiddle.net/EpLA7/
Related
I have a requirement to provide placeholder for all controls in my TPC form. I wanted to know if there is a way to do so. I have tried placing placeholder in Template like:
<input id='#Html.GetUniqueId(Model.Name)_input' data-tpc-role="lookup-input" name="#Model.MetaField.FieldName" data-tpc-default-value="#Model.GetLookupValue()" data-tpc-value="#Model.GetLookupValue()"
placeholder ="myplaceholdertext" type="text" #MvcHtmlString.Create(#Model.ValidationAttributes) data-tpc-custom-validation="lookup"/>
and through script
$(document).on("tpc:ready", function(){
var picklistName = "mypicklistname";
//Set Text to Placeholder Value
tpc.forms[0][picklistName].get_kendoInput().text("Please select an option.");
});
None of these work.
Let me know if this is the correct forum to ask TPC related questions
TIA
You have the kendo control but the value you want to set is the first item in its dataSource. Don't forget to refresh the control to make it show:
$(document).on("tpc:ready", function(){
var picklist = tpc.forms[0]["mypicklistname"];
//Set Text to Placeholder Value
picklist.get_kendoInput().dataSource.data()[0].Label = "Please select an option.";
picklist.get_kendoInput().refresh();
});
Unable to find the Element, tried few ways but unable to get to the element
Picture 1:
id="1_s_1_l_MTO_Transaction_Type" and Class="" (is empty)
In the picture, the highlighted HTML (Document_For) is the next field and you can see Class being added as class="edit-cell ui-state-highlight
Picture 2:
The desired field is highlighted in this picture and id="1_s_1_l_MTO_Transaction_Type" and Class="edit-cell ui-state-highlight" and New HTML is added
<input id="1_MTO_Transaction_Type"...........
I tried the below:
driver.findElement(By.id("1_s_1_l_MTO_Transaction_Type")).click();
driver.findElement(By.xpath(("//tr[starts-with(#class,'ui-widget-content') and #role='row']//td[id='1_s_1_l_MTO_Transaction_Type']"))).click();
driver.findElement(By.xpath(("//tr[#id='1']/td[id='1_s_1_l_MTO_Transaction_Type']"))).click();
All the above gave me Unable to find element
Picture 3:
More HTML to figure out how to find element
It will be a great Help as I have a series of Elements to find in the same way.
Select the Transaction Type using the id and follow the code below.
// Select Transaction Type
String Transaction_Type = ExcelUtils.getCellData(8, 2);
driver.findElement(By.xpath(("//td[contains(#id,'Transaction_Type')]"))).click();
driver.findElement(By.id("s_1_2_47_0_icon")).click();
driver.findElement(By.xpath("//li[#class='ui-menu-item']/div[contains(text(), '" + Transaction_Type + "')]")).click();
Map the column and click on an index (as i'm seeing, when the column cell is clicked, the input field is created, so you have to click it first)
Try it like this (this is C#, java below):
List<IWebElement> TransactionTypeFields => driver.FindElements(By.CssSelector("td[id*='Transaction_type']"));
IWebElement TransactionTypeInput => driver.FindElement(By.CssSelector("td[id*='Transaction_type'] input"));
public void TypeInTransactionTypeCell(string value, int index)
{
TransactionTypeFields[index].Click();
TransactionTypeInput.SendKeys(value);
}
in java, using your logic, should be something like this (there may be some syntax errors as im using notepad++):
public void TypeInTransactionTypeCell(string value, int index)
{
driver.findElements(By.cssSelector("td[id*='Transaction_type']")).get(index).click();
driver.findElement(By.cssSelector("td[id*='Transaction_type'] input")).sendKeys(value);
}
Let me know if it works!
I'm brand new to javascript, dojo and HTML and I've searched everywhere for examples of this and cannot find any.
I have a map with some feature points and a find task to highlight the feature points on the map, and display them in a grid with it's field attributes. This works great when I specify the search field as:
findParams.searchFields = ["LOCATION"];
But if I add:
findParams.searchFields = ["LOCATION", "MODEL_NUM"];
The grid displays results from multiple fields (ie. searching for attributes in LOCATION "A" would also find attributes in MODEL_NUM containing the letter "A"). So I decided to add a drop down menu select to specify which field to search in (one at a time) so the results are more precise.
So I added the following dijit:
<select id="fieldSelect" data-dojo-type="dijit/form/Select" name="fieldSelect">
<option value="" selected="selected">Select a field</option>
<option value="MODEL_NUM">Model Number</option>
<option value="LOCATION">Location</option>
<option value="NUM_DEFICIENCIES">Number of Deficiencies</option>
<option value="INSTALL_DATE">Install Date</option>
</select>
I then modified the search field statement to:
findParams.searchFields = "[" + "\"" + dom.byId("fieldSelect").value +
"\"" + "]";
When I click my search button I get an Uncaught TypeError: a.join is not a function (FindParameters.js:5)
I hope this is enough information. Does anyone have a solution or a recommendation?
UPDATE
After a suggestion to pass an array and not a string to the findParams.searchFields, I made the following changes:
findParams.searchFields = [];
findParmas.searchFields.push(dom.byId("fieldSelect").value);
This still gave me attribute results from multiple fields. After running a couple small tests:
var selectedField = document.getElementById('fieldSelect').value;
var index = selectedField.options[selectedField.selectedIndex].value;
And:
var selectedField = dom.byId('fieldSelect').value;
I'm finding that in the Chrome developer tools debugger, when I created a breakpoint at that line and executed the statement, both examples had the value of selectedField as 'undefined'.
Is this an issue of not getting the value from the drop down select dijit?
If no value is passed to findParams.searchFields, the API assumes all fields are valid, which is why I'm getting attribute results from multiple fields.
Thanks.
Use dijit.byId instead of dom.byId.
The following works for me:
var value = dijit.byId("fieldSelect").value;
if ("" != value) {
findParams.searchFields = [value];
} else {
findParams.searchFields = ["MODEL_NUM", "LOCATION", "NUM_DEFICIENCIES", "INSTALL_DATE"];
}
I found the problem.
Ultimately it was the registry.byId that led me to the answer, I had to rearrange some code after I realized the searchFields was in the wrong function and not in the function that is called when I click the search button.
But when accessing the dijit, the only thing that worked was registry.byId to access the dijit node and pass the value of the selected value into my searchFields.
Thanks.
I have an Index page which shows a list of data. The list can be filtered by selection from a dropdown list. This works okay. The first item in the dropdown has a blank value and the text "(all users)." So, this does what you expect--it shows all values in the list if you don't select an item to filter by. The razor for this is pretty simple:
#using (Html.BeginForm())
{
#Html.Label("userName", "View user:")
#Html.DropDownList("userName", ViewBag.UserName as SelectList, new { onchange = "this.form.submit()" })
}
In addition to viewing the list of data on the page, I offer a text file download of the currently filtered items. The razor for this is also pretty simple:
#using (Html.BeginForm("Download", "Checkout"))
{
#Html.Hidden("userName", Request["userName"])
<input type="submit" value="Download Metadata from Checked Out Files" />
}
This works right IF there's something selected in the filter dropdown. But if nothing is selected, then Request["userName"] returns "System.Web.Mvc.SelectListItem". I want it simply to be blank as the dropdown list appears when nothing is selected. What happens is that the value System.Web.Mvc.SelectListItem is passed to my download action and treated as a filter value.
So, the question is how to make it so a blank selection in my filter dropdown is not mistaken for "System.Web.Mvc.SelectListItem."
Try changing your #Html.DropDownList to this overload, string.Empty gives you the default blank option in your dropdown
#Html.DropDownList("userName", ViewBag.UserName as SelectList, string.Empty, new { onchange = "this.form.submit()" })
I hope I didn't misunderstand your question!
I have a somewhat odd situation where I have dynamically generated fields on a form--all dropdown lists. The selections correspond to binary values that I want to sum together to form a bitmask. I'm generating the dropdowns this way:
<table class="center">
#foreach (var field in Model.Fields)
{
<tr>
<td>#field.DisplayText:</td>
<td>
#Html.DropDownList(field.FieldName, new SelectList(field.Options, "FlagValue", "Text", field.SelectedValue), "(doesn't matter)")
</td>
</tr>
}
</table>
This seems to work--as far as rendering the proper HTML in the view. But my controller is not receiving the selections in the fields. I tried this to loop through the dynamic fields.
In the code below, PatientSelectorEditor is my ViewModel.
private void GetFlagInfo(PatientSelectorEditor pse, out string description, out long flags)
{
description = null;
flags = 0;
// get list of all possible fields that could be in the view.
pse.Fields = InitPatientSelectorFields(0);
foreach (PriceFlagField field in pse.Fields)
{
foreach (var option in field.Options)
{
// was something selected here?
if (Request[field.FieldName].Equals(option.FlagValue))
{
description += ", " + option.Text;
flags += option.FlagValue;
}
}
}
}
The line that goes
Request[field.Name]
is not finding the dynamically generated fields in my view.
What am I doing wrong?
I figured out what I was doing wrong here. This line....
if (Request[field.FieldName].Equals(option.FlagValue))
needed an explicit string comparison like this
if (Request[field.FieldName].Equals(option.FlagValue.ToString()))