Lib.Web.Mvc: does it REALLY requires a buildSelect function?

211 Views Asked by At

I've been testing this library recently, and noticed that when mapping a model property with JqGridColumnEditable, we can specify dataUrl parameters so the library can acquire the data for a select input (EditType = JqGridColumnEditTypes.Select).

My question is simple: Do I really have to implement a buildSelect js function to actually create the options? I mean, I've searched EVERYWHERE for a json pattern to return so it could build it automatically, because I can't believe it's not implemented.

Does anyone know if it does automatically populate the select input upon receiving the json from dataUrl? What is the expected format? If it's not (yet) possible, what is your suggestion for accessing the select input from the buildSelect function in order to manually populate it? I've tried 'this', no quotes, and unsucessfully.

1

There are 1 best solutions below

0
On BEST ANSWER

Unfortunately this limitation is inside the jqGrid itself. You can check the documentation here - it clearly says that if you are using dataUrl the server must return ready to use select element or you need to use buildSelect function.

When you are using the buildSelect function you don't access the select element, you return one. It might look like this (this sample assumes that your data is collection of objects with Key and Name properties):

var buildSelectFunction = function(data) {
    var selectItems = JSON.parse(data.responseText);
    var selectMarkup = '<select>';

    if (selectItems && selectItems.length) {
        for (var i = 0; i < selectItems.length; i++) {
            var selectItem = selectItems[i];
            selectMarkup += '<option value="' + selectItem.Key + '">' + selectItem.Name + '</option>';
        }
    }

    return selectMarkup + '</select>';
};