Filtering integer columns in a Kendo grid based on user input

I am facing an issue with the grid I have set up, which includes multiple columns such as Id(integer) and Name(string). The change event is functioning properly for the Name column, but not for the ID column.

I would like this functionality to be implemented on the server side using Razor syntax.

As a newcomer to Kendo UI, any guidance on how to accomplish this would be greatly appreciated.

Below is the code snippet I am currently using:

@(Html.Kendo().Grid(Model).Name("ViewDataGrid")

    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Title(" ID").Width(150);
        columns.Bound(c => c.Name).Title(" Name").Width(150);

        })
    .HtmlAttributes(new { style = "height: auto; width: 2200px" })
    .Filterable(i => i.Mode(GridFilterMode.Menu | GridFilterMode.Row))
    .Sortable(s => s.AllowUnsort(false).SortMode(GridSortMode.MultipleColumn))
    .Selectable(selecting => selecting.Enabled(true))                               
    .Pageable(r => r.PreviousNext(true).PageSizes(new int[] { 10, 20, 30, 40, 50, 100 }))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .ServerOperation(false)
        .Events(e => e.Change("call"))
        ))
function call(e) {

    if (e.sender.filter.arguments[0].filters != null) {
        if (e.sender.filter.arguments[0].filters[0].value == "") {                     
            $('#ViewDataGrid').data('kendoGrid').dataSource.filter({});
        }
        else {
            var filterlength = e.sender.filter.arguments[0].filters.length;
            $filter = new Array();
            if (e.sender.filter.arguments[0].filters[0].field == "Id")
            $filter.push({ field: e.sender.filter.arguments[0].filters[0].field, operator: "eq", value: e.sender.filter.arguments[0].filters[0].value });
            else
            $filter.push({ field: e.sender.filter.arguments[0].filters[0].field, operator: "contains", value: e.sender.filter.arguments[0].filters[0].value });
            $("#ViewDataGrid").data("kendoGrid").dataSource.filter($filter);

        }
    }
}

Model.CS

public int Id { get; set; }
public string Name { get; set; }

Controller

public ActionResult Index()
{
    List<GridData> dataList = new List<GridData>(); 
    GridData data1 = new GridData();
    data1.Id = 9191919;
    data1.Name = "XYZ";           
    dataList.Add(data1);
    return View(dataList);           
}

Answer №1

Consider utilizing the "row" selection type:

.Selectable(selecting => selecting.Enabled(true).Type(GridSelectionType.Row))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why isn't Google Map showing up in my HTML <div> section?

I am currently working on a web page that consists of two containers. The mainmapdiv container covers the entire page, while the mainhomediv container is positioned on top of the mainmapdiv. My goal is to hide the mainhomediv container and show a Google Ma ...

Can one use Javascript to access the Sharepoint REST API from an external source?

I'm looking to showcase the content of a Sharepoint list on an external webpage. I'm interested in using Javascript or PHP to make a REST call to Sharepoint for this purpose. Although I've researched Sharepoint's REST API, I'm uns ...

Unable to access the length of a scope variable after it has been modified

Within my HTML markup, I have a ng-init="find()" which triggers this particular function: $scope.find = function() { $scope.vehicles = Vehicles.query(); $scope.vehiclesQtd = $scope.vehicles.length; }; The issue arises when even though the vehicle ...

Is it possible to programmatically alter the clipboard using Javascript without requiring any user interaction?

I'm developing a script to simplify the reformatting of copied text, specifically phone numbers. I aim to paste the text into a textbox and have the formatted output automatically copied to my clipboard to reduce manual efforts. The function for upda ...

Angular Bootstrap modal not showing up (backdrop changes but modal is missing)

I've developed a custom directive featuring a button and an associated modal. Since this directive is being utilized twice on the same page, I needed to include additional attributes that can be passed to the template in order to establish unique IDs. ...

Filtering a 2-dimensional array based on a specific string match

I have an array with various objects and I am trying to find all objects that have the string "en-GB". However, I am encountering an issue with my current approach that gives me the error message "Cannot use 'in' operator to search for 'en&a ...

Steps for setting a new object as the default argument object

Consider the following scenario where we define a default state in a reducer: const defaultState = {...}; export const userReducer = (state = defaultState, action: any) => { // ... } Is there a way to have a new defaultState object created for eac ...

Empty results received from MongoDB queries executed within an asynchronous loop

I'm encountering an issue where I have a list of IDs that I need to query Mongo with in a for loop, but it always returns an empty []. Initially, the queries were returning promises, so I switched from using forEach to a standard for loop as shown her ...

Is it possible to have conventional ASP.NET Web Applications within Virtual Directories as part of an MVC Site?

For years, I've had a parent ASP.NET web application at www.MySite.co.uk with multiple child sites in virtual directories like www.MySite.co.uk/Client1. These sites are all traditional ASP.NET web forms applications using .NET 4.5 and have been workin ...

Encountering a Problem with ContentEditable in AngularJS

Here is the code snippet I am working with: <!doctype html> <html ng-app="flyerGen"> <head> <script src="http://code.angularjs.org/1.0.5/angular.min.js"></script> <script> angular.module('flyerGen', []).direct ...

Struggling to format pictures with instafeed.js

I am currently working on a website section that utilizes instafeed.js to display the three most recent images from an Instagram account. The images are loading correctly, but I need some guidance on how to style them appropriately. Unfortunately, the HTML ...

Why isn't the email validation functioning properly when implemented through data annotation in my view?

I'm encountering an issue with my email validation logic in an ASP.NET MVC form. The email field is designed for both model and view, but there doesn't seem to be any error indicated by the browser when I inspect it. Here's a snippet of the ...

Each time the page is reloaded, the animation's frames per second (fps

In my project, I have two main pages: 'index' and 'about'. The 'about' page includes a cool animation that you can check out here. The issue I'm facing is that when I navigate from the 'index' page to the &apos ...

Discovering the process of mapping transitions in MUI

I'm struggling with mapping my products in mui and placing each one in Grow. However, I keep getting this error message: "Warning: Failed prop type: Invalid prop children of type array supplied to ForwardRef(Grow), expect a single ReactElement". Can a ...

Implementing experimental decorators and type reconciliation in TypeScript - A step-by-step guide

My basic component includes the following code snippet: import * as React from 'react'; import { withRouter, RouteComponentProps } from 'react-router-dom'; export interface Props { }; @withRouter export default class Movies extends R ...

Receiving a console notification about a source map error

Recently, I started receiving this warning in my console: "Source map error: request failed with status 404" resource URL: map resource URL: shvl.es.js.map" Has anyone encountered this issue before? I'm unsure of what it might be? This is my webpa ...

You are unable to access the property outside of the callback function of the XMLHttpRequest

Currently, I am attempting to retrieve data from an XMLHttpRequest's onreadystatechange callback. Logging the data works perfectly fine within the callback function. However, when I try to use this data outside of the callback function with this.proce ...

Issue: Typescript/React module does not have any exported components

I'm currently facing an issue with exporting prop types from one view component to another container component and using them as state type definitions: // ./Component.tsx export type Props { someProp: string; } export const Component = (props: ...

Keep the Bootstrap dropdown menu open when the search bar is in focus

I am working on a customized bootstrap dropdown menu that needs to remain open when the search bar within the Events dropdown is focused. I have managed to make it open and close on hover, but now I need it to stay open under certain conditions. Below is ...

How to handle passing null values to an ASP .NET MVC controller using jQuery ajax

I've been encountering an issue where I am trying to send a stringified array from the view using $.ajax, but I keep receiving null in the controller function. Here's the code for the controller: [HttpPost] public void SaveColumnsToDb(str ...