This is a migrated thread and some comments may be shown as answers.

Date Selected & Format in grid

0 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 26 Jan 2012, 05:31 PM
Hi,

I need the ability to have the following:

1) Set the selected date of the datepicker in a grid.
2) Format the date picker and the date in the grid column.

Here is my code for you:

$(document).ready(function () {
 
       //kendo.toString(new Date(), "MM/dd/yyyy")
 
           
            
           dataSource = new kendo.data.DataSource({
               serverPaging: true,
               serverSorting: true,
               batch: true,
               pageSize: 100,
               transport: { read: { url: "@Url.Action("Read", "Animals")", type: "POST" },
                           update: { url: "@Url.Action("Update", "Animals")", type: "POST" },
               parameterMap: function (data, operation) {
                   alert(operation);
                    if (operation != "read") {
                       // post the Animals so the ASP.NET DefaultModelBinder will understand them:
 
                       var result = {};
 
                        //alert(data.models.length);
                        //alert(data.models);
                         
                       for (var i = 0; i < data.models.length; i++) {
                           var animal = data.models[i];
 
                           for (var member in animal) {
                               result["animals[" + i + "]." + member] = animal[member];
                           }
                       }
 
                       return result;
                   }
               }},
               schema: { model: { id: "AnimalId", fields: { AnimalId: { editable: false, nullable: false }, Name: {editable: true, nullable: false, validation: { required: true }}, Description: {editable: true, nullable: false, validation: { required: false }},
               FatherName: {editable: false}, MotherName: {editable: false}, BeginDate: {type: "date", editable:true, nullable:true, validation: { required: true }}, EndDate: {type: "date", editable:true, nullable:true, validation: { required: true }} }}},
               success: function (data) { debugger; alert(data.d.Text); },
               error: function (xmlHttpRequest) { debugger; alert("Sorry, we encountered the error: " + xmlHttpRequest.responseXML.text + " Please try again."); }
           });
 
           $("#grid").kendoGrid({
               dataSource: dataSource,
               scrollable:
                            { virtual: true },
               toolbar: ["create", "save", "cancel"],
               sortable: true,
 
               columns: [{ field: "Name" }, { field: "Description"}, { field: "BeginDate", title: "Date of Birth"}, { field: "EndDate", title: "Date of Death"},  { field: "FatherName", title: "Father"}, { field: "MotherName", title: "Mother"}],
               editable: true
           });
       })

Thanks for your help!

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Share this question
or