1

Found answers in Oleg post but unable to solve in my case. I have a jqGrid with inline editing. That works fine. One column 'SupervisorUserID' has a dropdown box with list of entries which retrieved from a database query already.

As the entries are too much, I want to have an input field which will autocomplete/search the dropdown list.

Please help me to achieve this. Thanks.

My code,

 public JsonResult PersonnelManagementGrid(string sidx, string sord, int page, int rows)
 {
    objPersonnelManagementViewModel = new PersonnelManagementViewModel();
    objPersonnelManagementViewModel.PersonnelManagementModelList = (List<PersonnelManagementModel>) Session["PersonnelList"];
    var results = objPersonnelManagementViewModel.PersonnelManagementModelList.Select(x => new
    {
        x.UserID,
        x.Name,
        x.InActive,
        x.SupervisorUserID,
    });

    int pageIndex = Convert.ToInt16(page) - 1;
    int pageSize = rows;
    int totalRecords = results.Count();
    var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
    if (sord.ToUpper() == "DESC")
    { results = results.OrderByDescending(e => e.Name); }
    else { results = results.OrderBy(e => e.Name); }
    results = results.Skip(pageIndex * pageSize).Take(pageSize);

    var sbLocations = new System.Text.StringBuilder();
    Dictionary<string, string> personnelList = new Dictionary<string, string>();
    personnelList = objPersonnelManagementViewModel.PersonnelManagementModelList.ToDictionary(x => x.UserID, x => x.Name);
    //personnelList.Add("1","one");
    //personnelList.Add("2", "two");
    //personnelList.Add("3", "three");
    foreach (var sortedLocation in personnelList)
    {
        sbLocations.Append(sortedLocation.Key);
        sbLocations.Append(':');
        sbLocations.Append(sortedLocation.Value);
        sbLocations.Append(';');
    }
    if (sbLocations.Length > 0)
        sbLocations.Length -= 1; // remove last ';'

    var jsonResults = new
    {
        colModelOptions = new
        {
            SupervisorUserID = new
            {
                formatter = "select",
                edittype = "select",
                editoptions = new
                {
                    value = sbLocations.ToString()
                }
            }
        },
        total = totalPages,
        page,
        records = totalRecords,
        rows= results,
    };
    return Json(jsonResults, JsonRequestBehavior.AllowGet);
}

Jquery:

$(function () {
$("#PersonnelManagementGrid").jqGrid({
    url: '/PersonnelManagement/PersonnelManagementGrid',
    datatype: "json",
    contentType: "application/json; charset-utf-8",
    mtype: 'Get',
    colNames: ['UserID', 'Name', 'Role', 'Active?', 'Supervisor', 'Change Active', 'Try Delete'],
    colModel: [
        { key: true, name: 'UserID', index: 'UserID', hidden: true },
        {
            name: 'Name', index: 'Name', editable: false, width: "460", sortable: true,
        },
        {
            name: 'Role', index: 'Role', editable: false, width: "200", sortable: true,
        },
        {
            name: 'InActive', index: 'InActive', editable: false, width: "200", sortable: true,                
        },
        {
            name: 'SupervisorUserID', index: 'SupervisorUserID', editable: true, formatter: 'select', width: "200", sortable: true,
            edittype: 'select', width: "200", align: "center",
        },
        {
            name: "Change Active", sortable: false, width: "200", align: "center",
            formatter: function (cellvalue, options, rowObj) {
                var cBtn = '<input type="button" class="button" value="Change" onclick= "changeActive(' + "'" + rowObj.id + "','" + "values" + "','" + "values" + '\')"/>'
                return cBtn;
            }
        },
        {
             name: "Try Delete", sortable: false, width: "200", align: "center",
             formatter: function (cellvalue, options, rowObj) {
                 var cBtn = '<input type="button" value="Delete" onclick= "tryDelete(' + "'" + rowObj.id + "','" + "values" + "','" + "values" + '\')"/>'
                 return cBtn;
             }
        }

    ],
    beforeProcessing: function (response) {
        var $self = $(this),
        options = response.colModelOptions, p;
        if (options != null) {
            for (p in options) {
                if (options.hasOwnProperty(p)) {
                    $self.jqGrid("setColProp", p, options[p]);
                }
            }

        }
    },
    pager: jQuery('#pager'),
    rowNum: 15,
    rowList: [5, 10, 15],
    height: '100%',
    width: '1328',
    viewrecords: true,
    caption: 'Personnel Management',
    //loadonce: true,
    emptyrecords: 'No records to display',
    scrollerbar: false,
    jsonReader: {
        root: "rows",
        page: "pagenumbers",
        total: "totalnumbers",
        records: "records",
        repeatitems: false,
        id: "0"
    },
    hidegrid: false,
    multiselect: false,
    onSelectRow: function (id) {
        rowSelect(id);
    },
}).navGrid('#pager', { edit: false, add: false, del: false, search: false, cancel: false, reload: false, refresh: false });    
});
Kavitha
  • 147
  • 8
  • Please include in all your questions the information about the version of jqGrid, which you use and from which fork of jqGrid. It's helpful too to post approximate number of items in the grid (100, 1000, 10000, 100000, ...). The information "the entries are too much" is too unclear. Moreover you don't use the standard ways of integration of inline editing (`formatter: "actions"`, `inlineNav` and so on). You want to use autocomplete in inline editing, but you don't included any code, which shows how you start/use inline editing. – Oleg Jan 12 '17 at 10:49
  • By the way, your current code of server code seems to implement server-side sorting incorrectly: if sort always by `Name` column. Isn't so? – Oleg Jan 12 '17 at 10:51
  • One more remark. Look at [the old answer](http://stackoverflow.com/a/7392816/315935) and [this one](http://stackoverflow.com/a/6080945/315935) – Oleg Jan 12 '17 at 11:01
  • @Oleg: Thanks a lot for quick comments. Sorry forgot to mention. I am using Jquery.jqgridv4.4.4. Actually, the dropdown contains list of 100-1000 values. If i select a row, the dropdown cell for that particular row will become editable, What i want here is, i need a input field along with the my dropdown to type the inputs which will search and list the values inside the dropdown. For eg: if i type "K", K related values needs to be listed inside the dropdown, likewise the dropdown list values should change according to my running inputs. Please suggest me to achieve this. – Kavitha Jan 12 '17 at 11:06
  • @Oleg: Moreover, i do not want the filter toolbar and also i need to work on sorting. – Kavitha Jan 12 '17 at 11:09
  • The number of items can't be larger as the total number of rows in the grid. The performance of new versions is must better especially in modern web browsers. [The demo](http://www.ok-soft-gmbh.com/jqGrid/OK/performane-13-5000-25-free-jqgrid.htm) displays 5000 rows with 13 columns in 25 rows per page. You can see the performance. Typical rountrip time to the server is higher in internet scenarios and the usage of small number of items (like 100-1000 in your case) could be better done by usage of `loadonce: true` and using jQuery UI Autocomplete of [select2](https://select2.github.io/) locally. – Oleg Jan 12 '17 at 11:14
  • @Oleg: Sorry, i think you have misunderstood (like 100 -1000) i mentioned about the dropdown values not the row list. Moreover, i didnt required filter toolbar. I'm completely asking about the dropdownlist values. Is that possible to bring Autocomplete functionality in my dropdown(available in all rows in my jqgrid). Thanks for clear comments. – Kavitha Jan 12 '17 at 11:24
  • I posted already references to two old answers [this one](http://stackoverflow.com/a/7392816/315935) and [another one](http://stackoverflow.com/a/6080945/315935), which describe the usage of jQuery UI Autocomplete. I repeat my main suggestion to you: start with upgrading from retro version 4.4.4 to free jqGrid 4.13.6 because of usage 4 years old version now is really bad choice. The goal of stackowerflow is sharing *common questions* and *common solutions*. I don't think that somebody else has an interst to use retro versions of jqGrid. Sorry. – Oleg Jan 12 '17 at 11:29

0 Answers0