Question

I've been doing alot of searching but haven't found a clear answer for this. I have a set up textboxes that and a submit button and a Kendo UI grid. I want to post the data to the grid's datasource so that it will return the results based on the criteria. I am not using the MVC wrappers.

EDIT: I've gotten closer but I can't seem to get the datasource to send the post data when I click submit. I've debugged and in my $("#fmSearch").submit it is hitting the jquery plugin and I've confirmed that it is converting the form data to JSON properly, but it seems as though it it not sending the updated information to the server so that the Action can read it.

Javascript

var dsGalleryItem = new kendo.data.DataSource({
        transport: {
            read: {
                url: '@Url.Content("~/Intranet/GalleryItem/SearchGalleryItems")',
                type: "POST",
                data: $("#fmSearch").serializeFormToJSON(),
                cache: false
            }
        },
        schema: {
            model: {
                id: "galleryItemID",
                fields: {
                    galleryItemID: {
                        nullable: true
                    },
                    imageName: {},
                    collectionName: {},
                    categoryName: {},
                    lastUpdatedOn: { type: "date" }
                }
            }
        }
    });




    var gvResults = $("#gvResults").kendoGrid({
        autoBind:false,
            columns: [{
                field: "imageName",
                title: "Item Name",
                template: "<a href='@Url.Content("~/Intranet/GalleryItem/Details/")#=galleryItemID#'> #=imageName#</a>"
            }, {
                field: "collectionName",
                title: "Collection"
            }, {
                field: "categoryName",
                title: "Category"
            }, {
                field: "lastUpdatedOn",
                title: "Last Updated",
                format: "{0:M/d/yyyy}"
            }
            ],
            selectable: "row",
            change: onRowSelect,
            dataSource: dsGalleryItem
        });






    $("#fmSearch").submit(
        function (event) {
            event.preventDefault();
            dsGalleryItem.read({ data: $("#fmSearch").serializeFormToJSON() });
    });

MVC Action

[HttpPost]
    public JsonResult SearchGalleryItems(string keyword, int? category, int? collection, DateTime? startDate, DateTime? endDate)
    {

        var galleryItemList = (from g in db.GalleryItems
                               //where g.imageName.Contains(keyword)
                               select new GalleryItemViewModel
                               {
                                   galleryItemID = g.galleryItemID,
                                   imageName = g.imageName,
                                   collectionName = g.collection.collectionName,
                                   categoryName = g.category.categoryName,
                                   lastUpdatedOn = g.lastUpdatedOn
                               });

        var galleryItemCount = Json(galleryItemList.ToList());

        return Json(galleryItemList.ToList()); ;
    }

The action is not setup to retrieve different data right now I just need to know how to connect the form to the grid.

Was it helpful?

Solution

Found the problem. I had this:

dsGalleryItem.read({ data: $("#fmSearch").serializeFormToJSON() });

It needed to be this:

dsGalleryItem.read($("#fmSearch").serializeFormToJSON());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top