jqgrid multiselect dropdown when using form edit
Asked Answered
E

1

1

This is the code of my multiselect dropdown column. It is working as I expected but I want some modification on edit mode.

{
    name: 'SubjectId',
    index: 'SubjectId',
    align: 'center',
    hidden: true,
    viewable: true,
    editrules: { edithidden: true },
    editable: true,
    formatter: 'select',
    editable: true,
    edittype: 'select',
    editoptions: {
        multiselect: true,
        dataUrl: '@Url.Action("getAllSubjects", "Subject")',
        //buildSelect: function (data) {
        //var retValue = $.parseJSON(data);
        buildSelect: function (data) {
            var response, s = '<select>', i;
            response = jQuery.parseJSON(data);
            // s += '<option value="0">--Select Subject--</option>';
            if (response && response.length) {
                $.each(response, function (i) {
                    s += '<option value="' + this.Id + '">' + this.SubjectName + '</option>';
                });
            }
            return s + '</select>';
        },

        dataInit: function (elem) {
            setTimeout(function () {
                $('#SubjectId').multiselect();
            }, 5);

        },
        multiple: true,
    }
},

But on edit mode I want to make multiselect false.How can do it.I don't understand how to do it.

Endue answered 9/1, 2014 at 9:27 Comment(0)
A
1

First of all your code has typing error: one should use dataInit instead of ddataInit.

If you need to use multiselect only in Add form and not in Edit form I would recommend you better don't use multiselect: true and dataInit. Instead of that you can use beforeShowForm callback (see the documentation). Inside of the callback you can set multiple attribute (see jQuery.attr) and call $('#SubjectId').multiselect();. If you would specify such beforeShowForm callback only for the Add form you should have the behavior which you require. Of case you should use recreateForm: true property for both Add and Edit forms.

Arria answered 9/1, 2014 at 11:28 Comment(2)
in add option I used below but not working as expected { recreateForm: true, closeOnEscape: true, reloadAfterSubmit: true, closeAfterAdd: true, beforeShowForm: function () { $.attr($('#SubjectId').multiselect() )Endue
@janina: 1) you should set multiple attribute of $('#SubjectId').attr("multiple", "multiple");. The code $.attr($('#SubjectId').multiselect() ) is definitively wrong. 2) You use buildSelect. So the call of $('#SubjectId').multiselect(); should be inside of setTimeout and all inside of beforeShowForm.Arria

© 2022 - 2024 — McMap. All rights reserved.