Happy New Year!
I want to place a label in a KendoUI Grid , When my page loads I am passing in the primary key of some table that refers to the description of the value I show in the label. It is working good when the page loads, BUT when I go to add a new row to the grid, it switches back and shows the primary key value in there.
Here is parts of how I have it currently setup:
In the schema of the grid I have added two fields:
ManagerPK: {
type: "number",
defaultValue : SearchVariable
},
ManagerName: {
type: "string"
}
And my Create/Update of the Kendo Grid are defined like this:
create: {
type: "POST",
url: "AddSomeRow",
dataType: "json",
contentType: "application/json"
},
update: {
type: "POST",
url: "UpdateSomeRow",
dataType: "json",
contentType: "application/json"
},
and in the columns definition of the grid for it I defined it like this:
columns: [
{
field: "ManagerPK",
title: "Manager Desc",
width: "8%",
template: "#=ManagerDesc ? ManagerDesc : ''#"
}
So how should I change my code to NOT SHOW the PK and always she the Description?
Related
sorry for the bad title I cannot express the proper subject to my problem
since, I'm a newbie in MVC and ajax I have a problem
In view I prepared a dropdown where it list all the shoes name (Shoe Table), now the customer has to select it but the twist it must display the Shoesprice (Shoe Table) once it select a shoe name. the view code is given below
View:
#Html.DropDownListFor(x => x.shoename, new SelectList(Model.ShoesModel,"shoename","shoename"), "Select Shoes Name", new {id="myDrop",#class="form-control" })
I have the script when you select it the item, this particular syntax is working
Script:
$("#myDrop").change(function ()
{
var value = $(this).val();
console.log(value);
$.ajax({
type: 'POST',
url: '/Customers/GetShoesPrice',
dataType: 'json',
data: { shoesName: $(this).val() },
success: function (data) {
//how can I declare a value to get the and return the price
}
});
}
But, i don't know how to create an ajax syntax (get the price according to shoe name), and set to a controller
thank you for help
Since you want to return single value only, just use data in AJAX success result to show returned price value:
Controller
[HttpPost]
public JsonResult GetShoesPrice(string shoesName)
{
var customerViewPrice = (from c in _SBC.Shoeses // Change the condition here
where c.shoename.Contains(shoesName)
select c.ShoesUnitPrice).FirstOrDefault(); // or SingleOrDefault() for one and only returned value
return Json(customerViewPrice);
}
View (jQuery)
$("#myDrop").change(function () {
var value = $(this).val();
console.log(value);
$.ajax({
type: 'POST',
url: '/Customers/GetShoesPrice',
dataType: 'json',
data: { shoesName: value },
success: function (data) {
// set input element value which will be posted on form submit with DropDownListFor
$('#price').val(data);
}
});
}
Note that if you want to show list of ShoesUnitPrice from selected shoesName, you need to use $.each() loop to iterate returned array of price value.
I have a kendo ui treeview and a dropdownbox on my asp.net mvc page. The dropdown box can have two values. Depending upon which one has been chosen, I want to change the datasource url, which is a method in a controller. The data type and structure of data from both the url will be the same. Essentially I want to change url: '#Url.Content("~/Document/GetMyDocument")' dynamically. The following is my treeview code:
<script>
$("#treeview").kendoTreeView({
checkboxes: {
checkChildren: true,
},
dataSource: {
transport: {
read: {
url: '#Url.Content("~/Document/GetMyDocument")',
type: "post",
dataType: "json"
}
},
schema: {
model: {
text: "Name",
spriteCssClass: "fa fa-folder",
children: "Files"
}
}
},
dataTextField: ["Name", "FileName"],
dataValueField: ["id"],
check: onCheck
});
You can specify the URL of the treeview dataSource as function
transport: {
read: {
url: function (e) { }
}
}
You can then listen for the change event of the DropDownList and call
$('#treeview').data('kendoTreeView').dataSource.read();
Inside the url function you can get the value of the DropDownList and resolve the url dynamically:
var ddl = $('#myDDl').data('kendoDropDownList');
var value = ddl.value();
return value == "someValue" ? "/foo/bar": "/bar/baz";
i am sending a ListofMap say 'ListofCSVMap' from my Grails(2.2.4) controller to Extjs (4.2.1) store
Like this
csvMap.put('Code', code)
csvMap.put('Number', number)
csvMap.put('Country', country)
listOfCsvMap.add(csvMap)
session.setAttribute("rows", listOfCsvMap)
render([items:listOfCsvMap] as JSON)
Now in my Extjs grid panel i am using the above listofCsvMap like this in my extjs store
var store1;
Ext.onReady(function() {
document.getElementById('legendId').style.display = "none";
store1 = new Ext.data.JsonStore({
storeId: 'myStore1',
pageSize: 20,
proxy: {
type: 'ajax',
url:'loadGrid',
reader: {
type: 'json',
root: 'items'
}
},
fields: ['Code','Number','Country']
});
i am editing a country using Roweditor Plugin like this
{
text : '<b>' + 'Country Of Origin' + '</b>',
//locked : true,
width : 110,
sortable : false,
dataIndex : 'Country',
editor : {
// for editable field, set a proper field xtype for it
xtype : 'combobox',
queryMode : 'remote',
editable : true,
id: 'countryDrop',
displayField : 'countryName',
valueField : 'countryName',
allowBlank : false,
store : new Ext.data.JsonStore({
proxy: {
type: 'ajax',
url: 'loadCountry',
reader: {
type: 'json'
}
},
autoLoad: true,
fields: [
{type: 'string', name: 'countryName'}
]
})
}
My requirement is when user edits the country field which is a combobox in the Extjs grid panel i want to return the entire updated Extjs store to my Grails Controller and update the listOfCsvMap which i am storing in session or is it possible to update the session attribute within the extjs grid it self after editing
Please help me with this !
I am using Kendo grid with .net mvc and angular. On some event i need to refresh datasource in grid (another url call) but with different parameter.
I know you can do this by setting dataSource.transport.options.read.url but is there any better way to do it? Like setting parameters on grid which datasource will read on each refresh?
This is my transport config
transport: { read: {
url: scope.model.readUrl,
type: scope.model.readAction || 'POST',
dataType: 'json',
},
and this is defining of the model (in a controller)
$scope.kendoGrid = {
showActions: true,
readUrl: /getPayPeriodReportForAllEmployees + "?dateTime=" + $scope.dateTime,
readAction: 'GET',
dataObjectName: 'Data',
totalObjectName: 'Total',
pageSize: 30,
fields: {
...
},
columns: [...]
}
So this $scope.dateTime is changeable, and if possible to tell that to the directive so i don't have to send it different url each time a chnage happens.
SO my problem is similar like this one http://www.telerik.com/forums/pass-a-parameter-to-a-datasource#aBBqFUSbE0-K3ecm1Q2fxg
I'm using Ruby on Rails, and I have a button that can create a post through AJAX, using this:
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader(
'X-CSRF-Token',
$('meta[name="csrf-token"]').attr('content'))},
url: "/posts/",
type: "POST",
data: {
post: {
title: "Cheese",
content: "Cake",
}
}
});
How do I format the data to create multiple posts at once, for example
posts = [
{
title: "Cheese",
content: "Cake"
},
{
title: "Key Lime",
content: "Pie"
}
]
so I can insert multiple objects with one POST?
I have a list of titles and contents. Might I have to construct a JSON object out of these?
Regardless of whether this is good Rails practice, how do I do this? Also, where might I look for how to format such HTTP requests?
Your jQuery call won't change much:
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader(
'X-CSRF-Token',
$('meta[name="csrf-token"]').attr('content'))},
url: "/posts/",
type: "POST",
contentType: "application/json",
data: JSON.stringify({
posts: [
{
title: "Cheese",
content: "Cake",
},
{
title: "Key Lime",
content: "Pie"
}
]
})
});
In your Rails action, you will be able to access your posts as an array of hashes via params[:posts].
class ThingsController < ApplicationController
def batch_create
params[:posts].each do |post|
Post.create post
end
end
end
Explanation
Using JSON.stringify causes your data to be serialized as JSON. Set contentType to application/json to add the "Content-Type: 'application/json'" header to your POST. That will clue Rails to interpret your POST as JSON.