While reorder the column in slickgrid, the header menu frozen column funtionality not working - slickgrid

While reorder the column in slickgrid, the header menu frozen column functionality is not working.
The below error thrown in console:
zone-evergreen.js:172 Uncaught TypeError: this.sharedService.visibleColumns is not iterable
at HeaderMenuExtension.executeHeaderMenuInternalCommands (angular-slickgrid.js:10948:1)
at HeaderMenu.<anonymous> (angular-slickgrid.js:10696:1)
at Event.notify (slick.core.js:104:1)
at HTMLDivElement.handleMenuItemClick (slick.headermenu.js:346:1)
at HTMLDivElement.dispatch (jquery.js:5183:1)
at HTMLDivElement.$event.dispatch (jquery.event.drag-2.3.0.js:387:1)
at HTMLDivElement.push.7TqN.$event.dispatch (jquery.event.drag-2.3.0.js:387:1)
at HTMLDivElement.elemData.handle (jquery.js:4991:1)
at ZoneDelegate.invokeTask (zone-evergreen.js:400:1)
at Zone.runTask (zone-evergreen.js:168:1)
My grid option
public gridOptions: GridOption = {
enableAutoSizeColumns: false,
// angular-upgrade
enableEmptyDataWarningMessage: false,
autoFitColumnsOnFirstLoad: false,
autoCommitEdit: true,
enablePagination: true,
pagination: { // Pagination UI - Item per page select options for default pagintation
pageSizes: [10, 15, 20, 25, 50, 75, 100, 200, 1000, 2000],
pageSize: 50
},
autoEdit: false,
rowHeight: 40,
headerRowHeight: 40,
enableCellNavigation: true,
editable: true,
enableAutoResize: true,
enableSorting: true,
enableFiltering: true,
enableExcelExport: true,
enableExport: true,
i18n: this.translateService,
gridMenu: {
hideExportExcelCommand: true,
hideExportCsvCommand: true,
customItems: [{
command: "cspfm-excel-export",
titleKey: "EXPORT_TO_EXCEL",
iconCssClass: "fa fa-file-excel-o",
action: (event, callbackArgs) => {
this.slickgridUtils.excelExport(event, callbackArgs, this.tempColumnDefinitions, this)
}
}, {
command: "cspfm-csv-export",
titleKey: "EXPORT_TO_CSV",
iconCssClass: "fa fa-download",
action: (event, callbackArgs) => {
this.slickgridUtils.excelExport(event, callbackArgs, this.tempColumnDefinitions, this)
}
},
{ divider: true, command: '', positionOrder: 90 },
{
command: "cspfm-appm-guide-fetch-mode-fully",
titleKey: "Full fetch",
iconCssClass: "icon-mat-explore",
action: (event, callbackArgs) => {
this.dataFetchMode = 'Full';
this.fetchModeChanged()
},
positionOrder: 91
}, {
command: "cspfm-appm-guide-fetch-mode-batch",
titleKey: "Batchwise fetch",
iconCssClass: "icon-mat-autorenew",
action: (event, callbackArgs) => {
this.dataFetchMode = 'Batch';
this.fetchModeChanged()
},
positionOrder: 92
}, {
command: "cspfm-appm-guide-fetch-mode-action",
titleKey: "On click batchwise",
iconCssClass: "icon-mat-touch_app",
action: (event, callbackArgs) => {
this.dataFetchMode = 'OnClickBatch';
this.fetchModeChanged()
},
positionOrder: 93
}, {
command: "cspfm-toggle-pagination",
titleKey: "Toggle pagination",
iconCssClass: "fa fa-bookmark",
action: (event, callbackArgs) => {
this.slickgridUtils.togglePagination(event, callbackArgs, this.gridObj, this.angularGrid)
},
positionOrder: 94
},
{
command: "cspfm-groupby",
titleKey: "Group-by",
iconCssClass: "icon-mat-account_tree",
action: (event, callbackArgs) => {
this.slickgridUtils.openDraggableGroupingRow(this.onGroupByEnabledObj, this.gridObj, "SearchList")
},
positionOrder: 95
}, {
command: "cspfm-clear-groupby",
titleKey: "Clear Grouping",
iconCssClass: "fa fa-times",
action: (event, callbackArgs) => {
this.slickgridUtils.clearGrouping(this.angularGrid, this.draggableGroupingPlugin, this.gridObj, this.gridOptions, this.filteredResultList, this.gridSearchRowToggle, this.onGroupByEnabledObj, this.filterSectionDetail)
},
positionOrder: 96
}
],
hideClearFrozenColumnsCommand: false
},
enableAutoTooltip: true,
autoTooltipOptions: {
enableForCells: true,
enableForHeaderCells: true,
maxToolTipLength: 1000
},
headerMenu: {
hideColumnHideCommand: true,
hideFreezeColumnsCommand: false
},
autoResize: {
containerId: this.gridContainerId,
calculateAvailableSizeBy: 'container'
},
exportOptions: {
exportWithFormatter: true
},
excelExportOptions: {
exportWithFormatter: true,
},
enableTranslate: true,
presets: {
sorters: [{ columnId: this.tableColumnInfo['pfm138993']['pfm138993_institutename_7']['prop'], direction: 'ASC' }],
},
enableAsyncPostRender: true, // for the Angular PostRenderer, don't forget to enable it
asyncPostRenderDelay: 0, // also make sure to remove any delay to render it
params: {
angularUtilService: this.angularUtilService // provide the service to all at once (Editor, Filter, AsyncPostRender)
},
enableDraggableGrouping: true,
createPreHeaderPanel: true,
showPreHeaderPanel: false,
preHeaderPanelHeight: 40,
draggableGrouping: {
dropPlaceHolderText: 'Drop a column header here to group by the column',
deleteIconCssClass: 'fa fa-times',
onGroupChanged: (e, args) => this.slickgridUtils.onGroupChanged(e, args, this.gridMenuExtension, this.angularGrid, this.tempColumnDefinitions, this.gridObj, this.draggableGroupingPlugin, this.gridOptions, this.layoutId),
onExtensionRegistered: (extension) => {
this.draggableGroupingPlugin = extension
}
},
enableColumnReorder: true,
alwaysShowVerticalScroll: false
};
Frozen column code in onAngularGridCreated:
angularGridReady(angularGrid: AngularGridInstance) {
this.angularGrid = angularGrid;
this.gridObj = angularGrid.slickGrid;
this.angularGrid.gridService.setPinning({ frozenColumn: 2 }, false, true, true);
}
Software Version:
Angular : 11.2.18
Angular-Slickgrid : 2.30.4
TypeScript : 4.0.8
Operating System : Windows 10
Node : 14.18.3
NPM : 6.14.15

Related

KendoUI populate dropdown

I am new to kendoUI and I need some assistance with getting the data that is returned from a function to populate into the dropdown. I am currently getting [object HTMLSelectElement] - you can see in the image attached. Any help is appreciated.
data is returned in function
dropdown is not showing the years returned
LoadAcceptedSubmissionsGrid: function (module) {
// Grid for "Accepted" tab
var isAccepted = "true";
gridAcceptedSubmissions = $("#gridAcceptedSubmissions").kendoGrid({
dataSource: {
type: "json",
serverPaging: true,
serverSorting: true,
serverFiltering: true,
allowUnsort: true,
transport: {
read: function (options) {
var strFilter = JSON.stringify(options.data.filter);
var strSort = JSON.stringify(options.data.sort);
var pageSize = options.data.pageSize === undefined && gridAcceptedSubmissions !== null ?
gridAcceptedSubmissions.dataSource.total() :
options.data.pageSize;
var acceptedSubmissionsUrl = commonUrl + "/Forms/Submissions/"
+ upacsSessionId + "/" + userId + "/" + form + "/" + isAccepted + "/"
+ options.data.page + "/" + pageSize + "/" + options.data.skip;
$.ajax({
type: "POST",
url: acceptedSubmissionsUrl,
xhrFields: {
withCredentials: true
},
data: {
filter: strFilter,
sort: strSort
},
success: function (response) {
options.success(response);
},
error: function (result) {
options.error(result);
}
});
}
},
pageSize: 10,
batch: false,
schema: {
total: function (response) {
return response.total;
},
data: function (response) {
return response.values;
},
model: {
id: "submissionId",
fields: {
state: { editable: false, type: "string", sort: "asc" },
fipsCode: { editable: false, type: "number", sort: "asc" },
year: { editable: false, type: "number", sort: "desc" },
name: { editable: false, type: "string" },
createdBy: { editable: false, type: "string" },
createdOn: { editable: false, type: "date" },
lastModifiedBy: { editable: false, type: "string" },
lastModifiedOn: { editable: false, type: "date" },
isEditable: { editable: false, type: "boolean" },
isReviewable: { editable: false, type: "boolean" }
}
}
}
},
groupable: false,
sortable: {
showIndexes: true,
mode: "multiple"
},
resizable: true,
selectable: "row",
scrollable: true,
filterable: true,
navigatable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 10
},
dataBound: this.GridDataBound,
columns: [
{
field: "submissionId",
title: "Id",
},
{
field: "state",
title: "State",
filterable: {
multi: true,
dataSource: this.BuildMultiCheckboxDataSource("state", "name", true)
},
sort: "ascending"
},
{
field: "year",
title: "Year",
filterable: {
multi: true,
dataSource: this.BuildMultiCheckboxDataSource("year", null, true)
},
sort: "descending"
},
{
field: "status",
title: "Status",
filterable: {
multi: true,
dataSource: this.BuildMultiCheckboxDataSource("status", null, true)
}
},
{
field: "createdBy",
title: "Initiated By",
filterable: {
ui: this.FormCreatedByAcceptedFilter
}
},
{
field: "createdOn",
title: "Initiated On",
format: "{0:g}",
},
{
field: "lastModifiedBy",
title: "Modified By",
filterable: {
ui: this.FormLastModifiedByAcceptedFilter
}
},
{
field: "lastModifiedOn",
title: "Modified On",
format: "{0:g}"
},
{
title: "Action",
headerTemplate: "<div class='headerTemplate'><span class='headerText'>Action</span>" +
"<button class='clearAllFilters' id='clearAllFiltersAcceptedSubmissions' tabindex=0> Clear All Filters</button></div>",
command: [
{
name: "View",
text: " ",
visible: function (dataItem) { return !dataItem.isEditable },
template: function () {
var tmpl = "<a role='button' class='k-button k-button-icontext k-grid-View' title='View Form' tabindex=0>" +
"<i aria-hidden='true' class='fa fas fa-eye'><span class='sr-only'>View form</span></i></a>";
return tmpl;
},
click: function (e) {
e.preventDefault();
var data = this.dataItem($(e.target).closest("tr"));
$("#submissionId").val(data.submissionId);
commonFormsModule.UpdateFormMetadata(data, "from-grid")
gridSubmissionStatusHistory.dataSource.read();
commonFormsModule.SwitchTo("view-existing-form", module);
}
},
{
name: "View History",
text: " ",
visible: function (dataItem) { return !dataItem.isReviewable },
template: function () {
var tmpl = "<a role='button' class='k-button k-button-icontext k-grid-ViewHistory' title='View Form History' tabindex=0>" +
"<i aria-hidden='true' class='fa fas fa-history'><span class='sr-only'>View form history</span></i></a> ";
return tmpl;
},
click: function (e) {
var data = this.dataItem($(e.target).closest("tr"));
$("#submissionId").val(data.submissionId);
commonFormsModule.UpdateFormMetadata(data, "from-grid")
gridSubmissionStatusHistory.dataSource.read();
commonFormsModule.SwitchTo("view-status-history", module);
}
}
],
},
]
}).data("kendoGrid");
gridAcceptedSubmissions.hideColumn(0);
$("#clearAllFiltersAcceptedSubmissions").click(function () {
gridAcceptedSubmissions.dataSource.filter({});
});
},
Without seeing what BuildMultiCheckboxDataSource is doing, I can only make assumptions.
However, since you have declared year as an IEnumerable<int> then the datasource does not need to be anything elaborate. Simply set it to the collection being returned by the server:
{
field: "year",
title: "Year",
filterable: {
multi: true,
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: "/my-endpoint-to-fetch-years-here"
}
}
})
},
sort: "descending"
}

Adding 750 rows into Datatables rows().add()

I am adding rows to a Datatable with the following code :
for (var key in itm) {
t.row.add([
null,
itm[key].itemcode,
itm[key].itemdesc,
itm[key].batch,
itm[key].expiry,
itm[key].qty,
itm[key].unit,
itm[key].rate,
itm[key].total,
itm[key].discper,
itm[key].discamt,
itm[key].staxper,
itm[key].staxamt,
itm[key].amount,
itm[key].netprate,
itm[key].salerate,
itm[key].page,
itm[key].sub1,
itm[key].sub2,
'<i class="fa fa-edit"></i>',
'<i class="fa fa-trash"></i>'
]).draw(false);
}
This is working fine except for the large data. When I try to add around 750 rows its too slow even the page hangs-up some times.
I tried to add the data using rows.add() API but its not working, the table is blank. Here is the code i am using to add bulk data.
var t = $('#productTable').DataTable();
t.rows.add(itm);
My datatable definition is as under :
$('#productTable').DataTable({
"paging": false,
"ordering": false,
"searching": false,
"info": false,
"rowHeight": '100px',
"scrollY": "200px",
"scrollX": true,
"scrollCollapse": true,
"paging": false,
"columns": [
{ data: null },
{ data: 'itemcode' },
{ data: 'itemdesc' },
{ data: 'batch' },
{ data: 'expiry' },
{ data: 'qty' },
{ data: 'unit' },
{ data: 'rate' },
{ data: 'total' },
{ data: 'discper' },
{ data: 'discamt' },
{ data: 'staxper' },
{ data: 'staxamt' },
{ data: 'amount' },
{ data: 'netprate' },
{ data: 'salerate' },
{ data: 'page' },
{ data: 'sub1' },
{ data: 'sub2' },
{ data: null },
{ data: null },],
"columnDefs": [
{ className: "dt-right", "targets": [7,8,9,10,11,12,13] },
{ "targets": varbatchcol, visible: false },
{ "targets": vardisccol, visible: false },
{ "targets": vartaxcol, visible: false },
{ "targets": vartotcol, visible: false },
{ "targets": [17,18], visible: false },
],
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
}
});
and the data coming from server is :
Found the problem.
t.rows.add(itm);
should be
t.rows.add(itm).draw();
And this also solved the slow populating issue.

Jqgrid cascading dropdown

Using jqgrid free latest version 4.15.2
I am trying to make cascading drop down from db.
I tried the sample as posted by #Oleg
jqgrid incorrect select drop down option values in edit box
But this is for older version of jqgrid and does not work fully while using latest version of jqgrid.
var countries = { "UsId": "US", "UkId": "UK" },
statesOfUS = { "AlabamaId": "Alabama", "CaliforniaId": "California", "FloridaId": "Florida", "HawaiiId": "Hawaii" },
statesOfUK = { "LondonId": "London", "OxfordId": "Oxford" },
states = $.extend({}, statesOfUS, statesOfUK),
allCountries = $.extend({"": "All"}, countries),
allStates = $.extend({"": "All"}, states),
// the next maps provide the states by ids to the contries
statesOfCountry = {
"": states,
"UsId": statesOfUS,
"UkId": statesOfUK
},
The entire code can be seen in fiddle below
https://jsfiddle.net/svnL4Lsv/
The issue is during the add form the second dropwdown shows all states instead of showing as per country
Secondly during the edit the second dropdown again shows all states and not as per the row value
Its just when I change the first dropdown does the second dropdown filters and works.
----------Updated
editoptions: {
// value: countries,
dataInit: dataInitApp,
dataEvents: dataEventsApp,
dataUrl: '#Url.Action("GetData", "Home")',
}
Controller code:
public enum Countries
{
USA = 1,
UK = 2
}
public enum State
{
Alabama = 1,
Florida = 2
London = 3
}
public JsonResult GetData()
{
var type = typeof(Helpers.UsersEnum.Countries);
var jsonData = Enum.GetNames(type)
.Select(name => new
{
Id = (int)Enum.Parse(type, name),
Name = name
})
.ToArray();
return Json(jsonData);
}
I call the above to populate my dropdown.
Also below is the json that is returned back:
[0]: {Id=1, Name="USA"}
[1]: {Id=2, Name="UK"}
[0]: {Id=1, Name="Alabama "}
[1]: {Id=2, Name="Florida"}
[2]: {Id=3, Name="London"}
In case of usage free jqGrid you can use a little simplified code
$(function () {
"use strict";
var countries = "usId:US;ukId:UK",
allStates = "alabamaId:Alabama;californiaId:California;floridaId:Florida;hawaiiId:Hawaii;londonId:London;oxfordId:Oxford",
// the next maps provide the states by ids to the countries
statesOfCountry = {
"": allStates,
usId: "alabamaId:Alabama;californiaId:California;floridaId:Florida;hawaiiId:Hawaii",
ukId: "londonId:London;oxfordId:Oxford"
},
mydata = [
{ id: "10", country: "usId", state: "alabamaId", name: "Louise Fletcher" },
{ id: "20", country: "usId", state: "floridaId", name: "Jim Morrison" },
{ id: "30", country: "ukId", state: "londonId", name: "Sherlock Holmes" },
{ id: "40", country: "ukId", state: "oxfordId", name: "Oscar Wilde" }
],
$grid = $("#list"),
changeStateSelect = function (countryId, countryElem) {
// build "state" options based on the selected "country" value
var $select, selectedValues,
$countryElem = $(countryElem),
isInSearchToolbar = $countryElem.parent().parent().parent().parent().hasClass("ui-search-table");
// populate the subset of countries
if (isInSearchToolbar) {
// searching toolbar
$select = $countryElem.closest("tr.ui-search-toolbar")
.find(">th.ui-th-column select#gs_list_state");
} else if ($countryElem.is(".FormElement")) {
// form editing
$select = $countryElem.closest("form.FormGrid")
.find("select#state.FormElement");
} else {
// inline editing
$select = $("select#" + $.jgrid.jqID($countryElem.closest("tr.jqgrow").attr("id")) + "_state");
}
if ($select.length > 0) {
selectedValues = $select.val();
if (isInSearchToolbar) {
$select.html("<option value=\"\">All</option>");
} else {
$select.empty();
}
$.jgrid.fillSelectOptions($select[0], statesOfCountry[countryId], ":", ";", false, selectedValues);
}
},
dataInitCountry = function (elem) {
setTimeout(function () {
$(elem).change();
}, 0);
},
dataEventsCountry = [
{ type: "change", fn: function (e) { changeStateSelect($(e.target).val(), e.target); } },
{ type: "keyup", fn: function (e) { $(e.target).trigger("change"); } }
],
cancelInlineEditingOfOtherRows = function (rowid) {
var $self = $(this), savedRows = $self.jqGrid("getGridParam", "savedRow");
if (savedRows.length > 0 && rowid !== savedRows[0].id) {
$self.jqGrid("restoreRow", savedRows[0].id);
}
};
$grid.jqGrid({
data: mydata,
datatype: "local",
colNames: [ "Name", "Country", "State" ],
colModel: [
{ name: "name", width: 180 },
{ name: "country", formatter: "select", stype: "select", edittype: "select",
searchoptions: {
noFilterText: "Any",
dataInit: dataInitCountry,
dataEvents: dataEventsCountry
},
editoptions: {
value: countries,
dataInit: dataInitCountry,
dataEvents: dataEventsCountry
}},
{ name: "state", formatter: "select", stype: "select", edittype: "select",
editoptions: { value: allStates }, searchoptions: { noFilterText: "Any" } }
],
cmTemplate: { width: 100, editable: true },
onSelectRow: cancelInlineEditingOfOtherRows,
ondblClickRow: function (rowid) {
cancelInlineEditingOfOtherRows.call(this, rowid);
$(this).jqGrid("editRow", rowid);
},
inlineEditing: {
keys: true
},
formEditing: {
onclickPgButtons: function (whichButton, $form, rowid) {
var $self = $(this), $row = $($self.jqGrid("getGridRowById", rowid)), countryId;
if (whichButton === "next") {
$row = $row.next();
} else if (whichButton === "prev") {
$row = $row.prev();
}
if ($row.length > 0) {
countryId = $self.jqGrid("getCell", $row.attr("id"), "country");
changeStateSelect(countryId, $form.find("#country")[0]);
}
},
closeOnEscape: true
},
searching: {
searchOnEnter: true,
defaultSearch: "cn"
},
navOptions: {
del: false,
search: false
},
iconSet: "fontAwesome",
sortname: "name",
sortorder: "desc",
viewrecords: true,
rownumbers: true,
pager: true,
pagerRightWidth: 85, // fix wrapping or right part of the pager
caption: "Demonstrate dependent selects (inline editing on double-click)"
})
.jqGrid("navGrid")
.jqGrid("filterToolbar");
});
see https://jsfiddle.net/OlegKi/svnL4Lsv/3/

Kendo grid returning only one record

I´ve been searching all over the net to find an answer to this problem but with no success, my problem is with my Kendo ui grid which is returning just one record. The funny thing is, i have another grids that are returning all the records correctly, so i simply using the same code but there´s got be a detail that is escaping me so i was hopping someone could point on that, this is the code i´m using (CRUD):
var dataSource = new kendo.data.DataSource({
transport:
{
read:
{
url: "data/clientes.php",
},
update:
{
url: "data/clientes.php?type=update",
type:"POST",
complete: function(e)
{
$("#gridClientes").data("kendoGrid").dataSource.read();
}
},
destroy:
{
url: "data/clientes.php?type=destroy",
type: "POST"
},
create:
{
url: "data/clientes.php?type=create",
type: "POST",
complete: function (e) {
$("#gridClientes").data("kendoGrid").dataSource.read();
}
},
parameterMap: function(options, operation)
{
if (operation !== "read" && options.models)
{
return {models: kendo.stringify(options.models)};
}
}
},
error:function(e)
{
console.log(e);
//alert(e.message);
},
batch: true,
pageSize: 8,
schema:
{
data: "data",
total: function(response)
{
return $(response.data).length;
},
model:
{
id: "idCliente",
fields:
{
idCliente: { editable: false, nullable: true, type: "number"},
titulo: { validation: { required: false } },
primeiroNome: { validation: { required: true } },
ultimoNome: { validation: { required: true } },
morada: { validation: { required: false } },
codigoPostal: { type: "string",validation: { required: false} },
cidade: { validation: { required: false } },
pais: { validation: { required: false } },
estado: { validation: { required: false } },
telefone: { type: "string", validation: { required: false, min: 1} },
email: { validation: { required: false } },
passaporte: { validation: { required: false } },
bi: { type: "number", validation: { required: false} },
foto: { type: "string", validation: { required: false} },
comentarios: { validation: { required: false } },
NomeUtilizadorCriador: {editable: true,validation: { required: false } },
DataCriacao: {editable: false, validation: { required: false } },
NomeUtilizadorUpdate: {editable: true, validation: { required: false } },
DataUpdate: {editable: false, validation: { required: false } },
}
}
}
});
$("#gridClientes").kendoGrid({
dataSource: dataSource,
height: 550,
serverPaging: true,
pageable : true,
toolbar:[{name: "create",text: $varGridQuartosBtnNovoPT},{name: "close",text: "X"}],
editable : {mode : "popup",
window : {title: "Editar",}
},
columns: [
{ field: "titulo", title: "Título", width: "8px", },
{ field: "primeiroNome", title: "Primeiro Nome", width: "14px" },
{ field: "ultimoNome", title: "Ultimo Nome", width: "14px" },
{ field: "morada", title: "Morada", width: "11px" },
{ field: "cidade", title: "Cidade", width: "11px" },
{ field: "codigoPostal", title: "CEP", width: "9px", editor:numberEditor },
{ field: "pais", title: "País", width: "14px" ,editor: paisEditor},
{ field: "estado", title: "Estado", width: "10px", hidden: true },
{ field: "telefone", title: "Telefone", width: "12px",editor:numberEditor},
{ field: "email", title: "Email", width: "17px" },
{ field: "passaporte", title: "Passaporte", width: "15px", hidden: true },
{ field: "bi", title: "Bi", width: "10px", hidden: true ,editor:numberEditor},
{ field: "foto", title: "Foto", hidden: true, editor:fotoEditor},
{ field: "comentarios", title: "Comentários", hidden: true, editor: textareaEditor},
{ field: "NomeUtilizadorCriador", title: "Criado por", hidden: true,editor:numberEditor},
{ field: "DataCriacao", title: "Criado em", hidden: true, width: "10px"},
{ field: "NomeUtilizadorUpdate", title: "Atualizado por", hidden: true, editor:numberEditor},
{ field: "DataUpdate", title: "Atualizado em", hidden: true, width: "10px"},
{command:[{ text: "Detalhes", click: showDetails },{ name: "edit",text:"Editar"},{ name: "destroy",text:"Apagar"}],title:" ",width: "30px"}],
});
If my database is empty and i insert just one record, then it returns that record correctly, but if i hit the new button to insert another record, it inserts in the database but the kendo grid returns/displays nothing, Meanwhile i have discovered a difference between this kendogrid and the others(that are working correctly) when i open the chrome console, this one returns two objects "data":
0: {,…}
data: {0: "70", 1: "", 2: "jonh", 3: "sousa", 4: "", 5: "", 6: "", 7: "", 8: "", 9: "", 10: "", 11: "",…}
1: {,…}
data: {0: "73", 1: "", 2: "joana", 3: "banana", 4: "", 5: "", 6: "", 7: "", 8: "", 9: "", 10: "", 11: "",…}
the other kendogrids, only return one object data, why? i do not know because i´m using the same code. I thought it could be something related with my .php file, but then if it was, it shouldn´t even insert one record right?.
I also have this error when i call the grid:
Object {xhr: Object, status: "parsererror", errorThrown: SyntaxError: Unexpected end of input, sender: ht.extend.init, _defaultPrevented: false…}
this error appears when my database is empty. If i have one record, then the erro disappears and as i said before the grid displays correctly, BUT the error returns if i insert another record.
Sorry for the long post, thanks for your time, any help would be very appreciated.
Regards

Set the selected text or value for a KendoDropDownList

I'm using Durandal and Kendo UI. My current problem is the edit popup event on my grid. I cannot seem to set the selected value on my dropdown.
I can debug and inspect, and I indeed do see the correct value of e.model.InstrumentName nicely populated.
How can I set the value/text of those dropdowns in edit mode ?
Here's my grid init:
positGrid = $("#positGrid").kendoGrid({
dataSource: datasource,
columnMenu: false,
{
field: "portfolioName", title: "Portfolio Name",
editor: portfolioDropDownEditor, template: "#=portfolioName#"
},
{
field: "InstrumentName",
width: "220px",
editor: instrumentsDropDownEditor, template: "#=InstrumentName#",
},
edit: function (e) {
var instrDropDown = $('#InstrumentName').data("kendoDropDownList");
var portfDropDown = $('#portfolioName').data("kendoDropDownList");
instrDropDown.list.width(350); // let's widen the INSTRUMENT dropdown list
if (!e.model.isNew()) { // set to current valuet
//instrDropDown.text(e.model.InstrumentName); // not working...
instrDropDown.select(1);
//portfDropDown.text();
}
},
filterable: true,
sortable: true,
pageable: true,
editable: "popup",
});
Here's my Editor Template for the dropdown:
function instrumentsDropDownEditor(container, options) {
// INIT INSTRUMENT DROPDOWN !
var dropDown = $('<input id="InstrumentName" name="InstrumentName">');
dropDown.appendTo(container);
dropDown.kendoDropDownList({
dataTextField: "name",
dataValueField: "id",
dataSource: {
type: "json",
transport: {
read: "/api/breeze/GetInstruments"
},
},
pageSize: 6,
select: onSelect,
change: function () { },
optionLabel: "Choose an instrument"
}).appendTo(container);
}
thanks a lot
Bob
Your editor configuration is bit unlucky for grid, anyway i have updated my ans on provided code avoiding manual selections:
Assumptions: Instrument dropdown editor only (leaving other fields as strings), Dummy data for grid
<div id="positGrid"></div>
<script>
$(document).ready(function () {
$("#positGrid").kendoGrid({
dataSource: {
data: [
{ PositionId: 1, Portfolio: "Jane Doe", Instrument: { IID: 3, IName: "Auth2" }, NumOfContracts: 30, BuySell: "sfsf" },
{ PositionId: 2, Portfolio: "John Doe", Instrument: { IID: 2, IName: "Auth1" }, NumOfContracts: 33, BuySell: "sfsf" }
],
schema: {
model: {
id: "PositionId",
fields: {
"PositionId": { type: "number" },
Portfolio: { validation: { required: true } },
Instrument: { validation: { required: true } },
NumOfContracts: { type: "number", validation: { required: true, min: 1 } },
BuySell: { validation: { required: true } }
}
}
}
},
toolbar: [
{ name: "create", text: "Add Position" }
],
columns: [
{ field: "PositionId" },
{ field: "Portfolio" },
{ field: "Instrument", width: "220px",
editor: instrumentsDropDownEditor, template: "#=Instrument.IName#" },
{ field: "NumOfContracts" },
{ field: "BuySell" },
{ command: [ "edit", "destroy" ]
},
],
edit: function (e) {
var instrDropDown = $('#InstrumentName').data("kendoDropDownList");
instrDropDown.list.width(400); // let's widen the INSTRUMENT dropdown list
},
//sortable: true,
editable: "popup",
});
});
function instrumentsDropDownEditor(container, options) {
$('<input id="InstrumentName" required data-text-field="IName" data-value-field="IID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataSource: {
type: "json",
transport: {
read: "../Home/GetMl"
}
},
optionLabel:"Choose an instrument"
});
}
</script>
Action fetching json for dropddown in Home controller:
public JsonResult GetMl()
{
return Json(new[] { new { IName = "Auth", IID = 1 }, new { IName = "Auth1", IID = 2 }, new { IName = "Auth2", IID = 3 } },
JsonRequestBehavior.AllowGet);
}

Resources