Note that there are some explanatory texts on larger screens.

plurals
  1. POKendo UI grid prevents updating image column
    primarykey
    data
    text
    <p>I am trying a <code>Kendo UI</code> grid implementation which has an image column as shown at below:</p> <pre><code>$("#grid").kendoGrid({ dataSource: dataSource, sortable: true, pageable: true, pageSize: 10, height: 400, toolbar: [{ name: "create"}], columns: [{ field: "ImageData", title: "Select Photo", width: 50, template: '&lt;img id="img_${PersonnelId}" src="/Admin/GetPersonnelImage?personnelId=${PersonnelId}" /&gt;' }, { field: "Name", title: "Name", width: 80 }, { field: "SurName", title: "Surname", width: 80 }, { field: "isActive", title: "Active", width: 40 }, { command: ["edit", "destroy", { name: "Photo", text: "Photo", click: Photo }], title: " ", width: "130px"}], editable: "inline", remove: function (e) { // remove }, save: function (e) { //save } }); } }); </code></pre> <p>Image column template makes <code>GET</code> requests to the following <code>ASP.MVC</code>action method in order to access its related image from database.</p> <pre><code>public FileContentResult GetPersonnelImage(int personnelId) { Personnel p = personnelRepository.GetById(personnelId); if (p != null) { return File(p.ImageData, p.ImageMimeType); } return null; } </code></pre> <p>As shown above, there is a custom command button named <code>Photo</code> which provides user to select an image file on a modal window. Following jQuery function running when user clicks this <code>submitPhoto</code> button on modal window:</p> <pre><code>var wnd, uploadTemplate, dataItem; function Photo(e) { e.preventDefault(); dataItem = this.dataItem($(e.currentTarget).closest("tr")); wnd.content(uploadTemplate(dataItem)); $("#imgfile").change(function (evt) { var f = evt.target.files[0]; var reader = new FileReader(); if (!f.type.match('image.*')) { alert("Selected file does not appear an image file! Please check your selection"); return; } reader.onload = function (e) { $('#preview').attr('src', e.target.result); }; reader.readAsDataURL(f); }); // Updates the src attribute of the grid image column $("#submitPhoto").click(function (e) { var pid = dataItem.PersonnelId; var imgPtr = "#img_" + String(pid); var v = $('#preview').attr('src'); $(imgPtr).attr('src', v); }); wnd.center().open(); } </code></pre> <p>The <code>src</code> attribute of the grid column is updating at the end of the above function. </p> <p>Everything works fine so far. However, grid makes <code>GET</code>requests to the action method immediately when modal window is closed and causes to lose new image selection. </p> <p>I would like to prevent <code>GET</code> requests while user editing data. I don't know what am I doing wrong here. Any suggestions would be really perfect. </p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload