Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- var lastsel;
- var mygrid = $("#list"),
- mygetUniqueNames = function (columnName) {
- var texts = mygrid.jqGrid('getCol', columnName), uniqueTexts = [],
- textsLength = texts.length, text, textsMap = {}, i;
- for (i = 0; i < textsLength; i++) {
- text = texts[i];
- if (text !== undefined && textsMap[text] === undefined) {
- // to test whether the texts is unique we place it in the map.
- textsMap[text] = true;
- uniqueTexts.push(text);
- }
- }
- return uniqueTexts;
- };
- var mydata = [
- { id: "1", Name: "Miroslav Klose", Category: "sport", Subcategory: "football" },
- { id: "2", Name: "Michael Schumacher", Category: "sport", Subcategory: "formula 1" },
- { id: "3", Name: "Albert Einstein", Category: "science", Subcategory: "physics" },
- { id: "4", Name: "Blaise Pascal", Category: "science", Subcategory: "mathematics" }
- ];
- jQuery(document).ready(function () {
- jQuery("#list").jqGrid({
- url: '@Url.Action("GetProductList")',
- datatype: 'json',
- loadonce: true, // to enable sorting on client side
- sortable: true, //to enable sorting
- ajaxSelectOptions: { type: "POST", dataType: "json" },
- mtype: 'GET',
- colNames: ['DSVareId', 'VendorId', 'EAN Nummer', 'Brand', '@Html.Encode(ViewData["Message1"])', '@Html.Encode(ViewData["Message2"])', '@Html.Encode(ViewData["Message3"])', 'Produkt Navn'],
- colModel: [
- { name: 'id', index: 'id', key: true, width: 65, editable: false, sortable: true, editrules: { edithidden: false} },
- { name: 'vendorId', index: 'vendorId', editable: true, sortable: true, editrules: { edithidden: false }, hidden: true },
- { name: 'EanNummer', index: 'EanNummer', width: 65, sortable: true, editable: true },
- { name: 'Brand', index: 'Brand', align: 'left', width: 50, sortable: true, editable: true, edittype: "select", editoptions: { dataUrl: '@Url.Action("GetBrands")',
- buildSelect: function (data) {
- var response = typeof (data) === "string" ? jQuery.parseJSON(data.responseText) : data;
- var s = '<select>';
- if (response && response.length) {
- for (var i = 0, l = response.length; i < l; i++) {
- var ri = response[i];
- s += '<option value="' + ri + '">' + ri + '</option>';
- }
- }
- return s + '</select>';
- }
- }
- },
- { name: 'Custom1', index: 'Custom1', align: 'left', width: 50, sortable: true, editable: true, edittype: "select", editoptions: { dataUrl: '@Url.Action("GetCustumer1")',
- buildSelect: function (data) {
- var response = typeof (data) === "string" ? jQuery.parseJSON(data.responseText) : data;
- var s = '<select>';
- if (response && response.length) {
- for (var i = 0, l = response.length; i < l; i++) {
- var ri = response[i];
- s += '<option value="' + ri + '">' + ri + '</option>';
- }
- }
- return s + '</select>';
- }
- }
- },
- { name: 'Custom2', index: 'Custom2', align: 'left', width: 50, sortable: true, editable: true, edittype: "select", editoptions: { dataUrl: '@Url.Action("getCustomer2")',
- buildSelect: function (data) {
- var response = typeof (data) === "string" ? jQuery.parseJSON(data.responseText) : data;
- var s = '<select>';
- if (response && response.length) {
- for (var i = 0, l = response.length; i < l; i++) {
- var ri = response[i];
- s += '<option value="' + ri + '">' + ri + '</option>';
- }
- }
- return s + '</select>';
- }
- }
- },
- { name: 'Custom3', index: 'Custom3', align: 'left', width: 50, sortable: true, editable: true, edittype: "select", editoptions: { dataUrl: '@Url.Action("GetCustumer3")',
- buildSelect: function (data) {
- var response = typeof (data) === "string" ? jQuery.parseJSON(data.responseText) : data;
- var s = '<select>';
- if (response && response.length) {
- for (var i = 0, l = response.length; i < l; i++) {
- var ri = response[i];
- s += '<option value="' + ri + '">' + ri + '</option>';
- }
- }
- return s + '</select>';
- }
- }
- },
- { name: 'ProductName', index: 'ProductName', sortable: true, editable: true },
- ],
- loadComplete: function () {
- if (grid.getGridParam('datatype') === 'json') {
- // build the set 'source' parameter of the autocomplete
- grid.jqGrid('setColProp', 'EanNummer', {
- searchoptions: {
- sopt: ['bw'],
- dataInit: function (elem) {
- $(elem).autocomplete({
- source: mydata,
- delay: 0,
- minLength: 0
- });
- }
- }
- });
- }
- jQuery("#list").trigger("reloadGrid", { stringResult: true, searchOnEnter: true, defaultSearch: "cn" }); // Call to fix client-side sorting
- },
- gridComplete: function () {
- var gr = jQuery('#list'); gr.setGridHeight("auto", true);
- },
- onSelectRow: function (id) {
- if (id && id !== lastsel) {
- jQuery('#list').jqGrid('restoreRow', lastsel);
- jQuery('#list').jqGrid('editRow', id, true);
- lastsel = id;
- }
- },
- autowidth: true,
- editurl: '@Url.Action("GridSave")',
- rowNum: 50000,
- rowList: [5, 10, 20, 50],
- sortname: 'DSVareId',
- sortorder: "desc",
- viewrecords: true
- });
- jQuery("#list").jqGrid('navGrid', "#page", { edit: false, add: false, del: false });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement