RadGrid- getting dropdownlist index using javascript - javascript

I have another issue with using RadGrid control from telerik.
I am trying to get/set the value of a GridDropDowncolumn in RadGrid using javascript (in edit mode). Could anyone suggest the appropriate javascript method to do this?
So I have the following RadGrid GridDropDownColumn:
<telerik:GridDropDownColumn DataField="ProjectileTypeId" HeaderText="Projectile Type"
DataSourceID="ProjectileTypesDataSource"
UniqueName="ProjectileType"
ListTextField="Name" ListValueField="Id" />
Now I am tring to get the current dropdown's selected index in javascript (during edit mode)
What I have at the moment is:
var radGrid = $get("RadGrid1");
var griddropdownlistElement = $telerik.findElement(radGrid, "ProjectileType");
However not sure of the appropriate javascript method to set/get the value.

you have to provide a index to each dropdown in the grid and based on that index you can get the selected index, to do this you can see the following example:
http://www.telerik.com/community/forums/aspnet/grid/get-dropdownlist-value-from-rad-grid.aspx

Related

Django Modelmultiplechoicefield Checkboxselectmultiple Problem Getting Selected Checkbox

I have been working all day to try and get the selected values on one set of checkboxes on my Django form and copy the selected ones only to an identical checkbox on my form. If a user clicks on a checkbox in form.author defined below, I want the same identical checkbox to automatically be checked on form.favorite_author defined below.
I've tried a JQuery approach as documented here...Copy Selected Checkbox Value From One Checkbox To Another Immediately Using JQUERY but no luck so far. I've recently begun exploring an avenue with the Modelmultiplechoicefield and the checkboxselectmultiple parameters within the form itself. From what I can tell, when I am using JQuery and trying to check a box on the form, the value is coming back as undefined which is most likely why it is not propagating the checkbox selection to the other checkbox.
Here is my form....
class ManagerUpdateNewAssociateForm(forms.ModelForm):
class Meta:
model = Library
self.fields['author'] = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple(),
queryset=Books.objects.all()
self.fields['favorite_author'] = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple(),
queryset=Books.objects.all()
My HTML...
<div class="spacer83">
{{ form.author }}
</div>
<div class="spacer83">
{{ form.favorite_author }}
</div>
When I tried to trace JQuery, it told me the checkbox selections are undefined. I did read a bit about how Modelmultiplechoicefield, since it uses a queryset it doesn't show the selections, but I can't figure out how to get it to.
Thanks in advance for any thoughts.
In combination with the other issue included in this one, I went back to the JQuery route and explored further. From what I can tell, I was not able to use the class for the input because of the way the HTML for Django forms is generated in this use case. I ultimately was able to leverage the input name and then used the code below to interrogate the checkboxes accordingly:
$(document).ready(function() {
$("[name=author]").change(function() {
let selectedValA = $(this).val();
let isAChecked = $(this).prop("checked");
$(`[name=favorite_author][value="${selectedValA}"]`).prop("checked", isAChecked);
});
});
});

How to select an Item from the Richfaces PickList sourceList using the javascript API?

I'm working with Richfaces 4.5.1 PickList component and I need to select an item from the source list using javascript. I'm looking to the javascript API from the Richfaces documentation and i'm able to use getSourceList() and add() functions without a problem. The documentation says that getSourceList() will give you the javascript list object to where you can select/unselect item(s). The problem is that it doesn't tell you the function name to select/unselect items. I can't use add() without first selecting an item.
Javascript function:
function refresh() {
var source = #{rich:component('customer')}.getTargetList();
INSERT CODE TO SELECT FROM source LIST
#{rich:component('customer')}.add();
}
Richfaces PickList:
<rich:pickList id="customer" value="#{payrollCreate.nameList}" listHeight="200" sourceCaption="Available Customers" targetCaption="Selected Customers" orderable="true">
<f:selectItems value="#{payrollCreate.clients}"/>
</rich:pickList>
can anyone help me with this?
Thanks...

Get Selected value from ui-grid using jquery/javascript

In My project,we used data grid using AngularJS Implementation as follows.
<div id="entityGrid" ui-grid="selectedOptions" ui-grid-selection data-ng-model="selectedOptions"></div>
i can get selected item in grid as below using angular.js .
"entity" : $scope.createString($scope.selectedOptions.data)
but i also want to get selected item in grid using jquery/javascript due to some requirement..
i tried to get value using jquery as below. but it didn't work.
var entity = $('#entityGrid option:selected');
please help here.
You question is not very clear. I wonder if you could provide a plunker of your codes.
Here is one:
http://plnkr.co/edit/3KXrUuCsSACuhefmyzxN?p=preview
When you click "Copy" button, the following function is invoked:
$scope.copySelection = function (){
$scope.retainSelection = $scope.gridApi.selection.getSelectedRows();
};
What you get in $scope.retainSelection is an object of key:value pairs. You can access which ever key of it.
Here is another question talking about this:
Where can I get Angular ui-grid selected items
Hope it helps.

PrimeFaces 3.2 Picklist : Getting Target-List On JavaScript Function

How to Traverse Picklist - TargetList and update the target list values to a ManagedBean List by using java script function.
Note: The version I am working not support ajax transfer event, I need to use onTransfer
Below my code.
<p:pickList id="pickListId" value="#{bean.legacySystem}"
onTransfer="bindTargetValues();" var="legacySys" widgetVar="pickListWV"
itemLabel="#{legacySys}" itemValue="#{legacySys}"/>
<script>
function bindTargetValues(){
//How to traverse and bind tragetList values to a managed bean object
}
</script>
If you want to access in the JavaScript the content of the both lists, there are hidden selects, suffixed with "_source" and "target".
So, $('[id$=pickListId_source] option') will return you all option elements representing the source list, and $('[id$=pickListId_target] option') the same, with target.
Than you can iterate the options and read value attribute to check which elements are in which list.

Fill textboxes based upon current Dropdownlist (database items) selection (asp.NET MVC)

I have a dropdown box in my view which is populated with objects from database. Now what I want to do is, based upon selection in the Dropdown fill various textboxes with property values of the object selected in the dropdownlist.
There are numerous examples where you copy the selected dropdown value in the textbox using JQuery / JavaScript etc, but I can't find any doing the same but instead of copying; place the values of the properties of the object in the textboxes.
How would this be done in a nice way? I would prefer to do it without posting the entire form, though those answers may be posted also.
$('select#yourControlId').change(function () {
var selectedVal = $(this).val();
document.location = '<%= Url.Action( "Action", "Controller") %>' + '?val=' + selectedVal;
});
Then you'll capture val in the signature of teh action method and populate the appropriate textboxes...
Or
You could also on Changed do a JQuery Ajax post...
http://api.jquery.com/jQuery.ajax/

Categories

Resources