We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Checkbox does not check when clicked

Thread ID:

Created:

Updated:

Platform:

Replies:

148665 Oct 29,2019 04:38 PM UTC Nov 5,2019 03:38 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Alexandre
Asked On October 29, 2019 04:38 PM UTC

The title says it all. When I click on the checkbox, there is no change of state of checkbox to Checked

My model:

    public class TituloPendente
    {
        public int TituloID { get; set; }
        public bool Selecionado { get; set; }
        public string NumeroDoDocumento { get; set; }
        public string NossoNumero { get; set; }
        public DateTime DataDeVencimento { get; set; }
        public decimal Valor { get; set; }
    }

My Home Controller:

    public class HomeController : Controller
    {
        private static readonly object objLock = new object();

        public ActionResult Index()
        {
            List<SyncfusionMvcApplication1.Models.TituloPendente> titulos = new List<Models.TituloPendente>();

            for (int i = 0; i < 100; i++)
            {
                Random rnd = new Random((int)Math.Cos((double)(i + 1)));

                lock (objLock)
                {
                    titulos.Add(new Models.TituloPendente()
                    {
                        TituloID = 1,
                        NumeroDoDocumento = (i + 1 * 8454548).ToString(),
                        NossoNumero = (i + 1 * 6544456).ToString(),
                        DataDeVencimento = DateTime.Now.AddDays(i),
                        Valor = (decimal)((15.02m * (i + 1)) + (decimal)((double)((i + 1) % 45646) / Math.Sqrt((double)(rnd.Next(1, 45645646))))),
                        Selecionado = false
                    });
                }
            }

            return View(titulos);
        }
    }

My View:
 ( in attachment )

Attachment: Index_dd8257a4.zip

Padmavathy Kamalanathan [Syncfusion]
Replied On October 31, 2019 02:40 AM UTC

Hi Alexandre,

Thanks for contacting Syncfusion Forums.

QUERY: CheckBox doesn't check when clicked

From the code you have shared, we can undestand that you are using "displayAsCheckbox" property for showing the column as check box column. When you use "displayAsCheckbox" property, you can check/uncheck it in edit mode(by double clicking the cell). 

Please let us know the below details, so that we can help you to achieve it,
1) Whether you need to check/ uncheck in single click
2) Please explain us your requirement with clarity(what you are trying to do with the check box)
3) Version Details
4) Screenshot of error with stacktrace(if any)

If you have further queries, please get back to us.

Regards,
Padmavathy Kamalanathan
 


Alexandre
Replied On November 1, 2019 09:07 PM UTC

Hi! I just need to have a checkbox to select some rows of the grid and send this selected rows to the controller... ( When change the page, the selection can't be lost )

Padmavathy Kamalanathan [Syncfusion]
Replied On November 5, 2019 03:38 AM UTC

Hi Alexandre,

Thanks for your update.

QUERY: Need to select some rows and send to controller 

From your query we understand that you need to select rows using checkbox and send the selectes rows to the controller. This can be done by following below steps,

1) Render checkbox as column using type property. Please check below help documentation,

2) Select checkboxes and in actionComplete event with requestType as "paging", you can get the selected records's primary key value and save it to array when you navigate from one page to other.
Please check below help documentations,

3) In button click event, using AJAX, you can send the selected Record's primary key value to controller. In Controller, you can compare the passed primary key value with your data model and perform your functionalities.

Please check below code,


@Html.EJ().Button("mute").Size(ButtonSize.Large).ShowRoundedCorner(true).ClientSideEvents(e => e.Click("click")).Text("Mute")

@(Html.EJ().Grid<object>("FlatGrid")
                .Datasource((IEnumerable<object>)ViewBag.datasource)
                                .AllowPaging()
                                .ClientSideEvents(eve => { eve.ActionComplete("actionComplete"); })
                                .Columns(col =>
                                {
                                    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
                                    col.Type("checkbox").HeaderText("check").Width(90).Add();
                                })
)


<script>
    var primaryKeyValuesArray = []; 
    function click(args) {
        var selectedData = primaryKeyValuesArray; // array of primary key values

        $.ajax({
              // pass to controller
        });
    }
    function actionComplete(args) {
        if (args.requestType == "paging") { 
            var data1 = this.model.selectedRecords, len1 = data1.length, arrayLength = primaryKeyValuesArray.length;
            for (i = 0; i < len1; i++) {
                var value = data1[i]["OrderID"]; // orderID is primarykey column field
                primaryKeyValuesArray.push(value);
                console.log(primaryKeyValuesArray);
            }
        }  
    }
</script>

If you have further queries. please get back to us.

Regards,
Padmavathy Kamalanathan


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon