On row expand wrong row is updated (grid, jsp)

3 posts, 0 answers
  1. Alex
    Alex avatar
    2 posts
    Member since:
    Jan 2014

    Posted 13 Jan 2014 Link to this post

    Hi kendo ui team,
    On expand i make post request which returns list from a hashmap depending on requested id. Each rendered list is a nested row inside grid with unique id.
    Issue is while expending each row i get only 1st nested row updated with results basically row id reference is missing and grid widget doesn't know which nested row to update. Any suggestions and recommendations appreciated.

    here is some code:
    JSP
    <%               
        HashMap<String, Object> data = new HashMap<String, Object>();
        data.put("itemId", "#=itemId#");
    %>
     
    <kendo:grid name="item" pageable="true" detailTemplate="template">
        <kendo:dataSource>
            <kendo:dataSource-transport>
                <kendo:dataSource-transport-read url="http://localhost:8080/GrubbyUI/api/items" />
            </kendo:dataSource-transport>
            <kendo:dataSource-schema data="data" total="total" />
        </kendo:dataSource>
        <kendo:grid-columns>
            <kendo:grid-column title="id" field="itemId"></kendo:grid-column>
        </kendo:grid-columns>
    </kendo:grid>
     
    <kendo:grid-detailTemplate id="template">
        <kendo:grid name="innerData">       
            <kendo:dataSource>
                <kendo:dataSource-transport>
                    <kendo:dataSource-transport-read url="http://localhost:8080/GrubbyUI/api/items"
                        data="<%=data %>" type="POST" contentType="application/json "/>
                    <kendo:dataSource-transport-parameterMap>       
                        <script>
                             function parameterMap(options) {
                                return JSON.stringify(options);
                             }
                        </script>
                     </kendo:dataSource-transport-parameterMap>                   
                </kendo:dataSource-transport>
            </kendo:dataSource>
            <kendo:grid-columns>
                <kendo:grid-column title="id" field="itemId"></kendo:grid-
               <kendo:grid-column title="Date Added" field="dateAdded"></kendo:grid-column>
            </kendo:grid-columns>           
        </kendo:grid>
    </kendo:grid-detailTemplate>
    Java servlet:

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         
        try {
            // objects for keeping data structures
            DataModel result = new DataModel();
            DataSourceResult data = new DataSourceResult();
            Gson gson = new Gson();
     
            data.setData(result.listOfItems());
            data.setTotal(result.getTotal());
             
            response.setContentType("application/json");
            response.getWriter().write(gson.toJson(data));
         
        } catch (Exception e) {
            response.sendError(500);
            e.printStackTrace();
        }
    }
     
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     
        Gson gson = new Gson();
               // some random data for testing purposes
        HashMap<String, List<Item>> data = new HashMap<String, List<Item>>(); // response data struct
        List<Item> l1 = new ArrayList<Item>();
        List<Item> l2 = new ArrayList<Item>();
        BufferedReader reader = request.getReader();
         
        String line = reader.readLine();
        Map<String, String> map = gson.fromJson(line, Map.class);
        String selectedId = map.get("itemId");
        System.out.println(selectedId);
     
        // init data var
        Item item1 = new Item("lib", "#1", false, "date");
        Item item2 = new Item("lib 2", "#2", true, "date");
        l1.add(item1);
        l1.add(item2);
        data.put("1", l1);
         
        item1 = new Item("lib 3", "#3", true, "date");
        item2 = new Item("lib 4", "#4", false, "date");
        l2.add(item1);
        l2.add(item2);
        data.put("2", l2);
         
        response.setContentType("application/json");
        response.getWriter().write(gson.toJson(data.get(selectedId)));
    }


  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 15 Jan 2014 Link to this post

    Hello Alex,

    I am not sure I understand the spot at which you struggle. Could you please point us where exactly in your code you are facing a difficulty to get reference to a row id?

    Basically the hierarchy demo demonstrates just the same:

    http://demos.kendoui.com/web/grid/hierarchy.html

    For the update operation you can do just the same to send additional arguments from the parent Grid to the update action method.

    Thank you in advance for the clarification.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET AJAX banner
  4. Alex
    Alex avatar
    2 posts
    Member since:
    Jan 2014

    Posted 15 Jan 2014 Link to this post

    I've made a careless mistake but now fixed it. Basically I ve renamed nested grid to 'grid_#=itemId#'. I think becomes a reference id to a nested grid
    see code:
    <%               
       HashMap<String, Object> data = new HashMap<String, Object>();
       data.put("itemId", "#=itemId#");
    %>
     
    <kendo:grid name="grid" detailTemplate="rowTemplate"
      .....
    </kendo:grid>
     
    <kendo:grid-detailTemplate id="rowTemplate">
      <kendo:grid name="grid_#=itemId#">
         ....
      </kendo:grid>
    </kendo:grid-detailTemplate >


Back to Top