Uncaught TypeError: e.slice is not a function on data fetch

16 posts, 0 answers
  1. Pavlos
    Pavlos avatar
    7 posts
    Member since:
    Dec 2014

    Posted 09 Oct 2015 Link to this post

    Hi!

    I'm trying to make an ajax call to my controller function.
    To get all the data that currently are in a grid's datasource.
    Instead of calling directly to the grid's datasource.data() which only returns me the current grid page.

    I go about this by instantiating a new kendo datasource.
    But everything i try, yields "Uncaught TypeError: e.slice is not a function"

    Thanks in advance.

    public JsonResult ReadTimeRegistrationAjax([DataSourceRequest] DataSourceRequest request)
    {
       var dataSourceResult = getStuff().ToList();
       return Json(dataSourceResult.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

    var grid = $("#GridTimeRegistrations").data("kendoGrid");
            var dataurl = grid.dataSource.transport.options.read.url;
     
            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: dataurl,
                        dataType: 'json'
                    }
                },
            });         
     
            dataSource.fetch(function() {
                var data = dataSource.data();
                console.log(data);
            }

  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 13 Oct 2015 Link to this post

    Hello Pavlos,

     

    Would it be possible to extract a runnable sample where the issue can be reproduced, as from the code shared here it is not possible for us to tell you why exactly this happens.

     

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 22 Oct 2015 in reply to Pavlos Link to this post

    Happens to me all the time too, what usually fixes it is providing a model for the data:

    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: dataurl,
                dataType: 'json'
            }
        },
        schema : {
            type: "json",
            data: "Item",
            model: {
                fields: {
                    Field1: { field: "Field1", type: "number" },
                    Field2: { field: "Field2", type: "number" }
                }  
            }
        }
    });

    (Also, I noticed when copying your code for my example, you've got a comma after the transport closing } that's not necessary).
  4. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 23 Oct 2015 Link to this post

    Hello shimmoril,

     

    Send us a sample of the data that you want to bind, so we can try to recreate the case and see what happens.

     

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 26 Oct 2015 in reply to Kiril Nikolov Link to this post

    I've posted about it before (http://www.telerik.com/forums/datasource-schema-model-for-templates) and didn't receive a helpful answer. Providing the schema model works 100% of the time though, and it's not a big deal to include it, so I dropped the original thread. I just wanted to share what worked for me w/ Pavlos.
  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 27 Oct 2015 Link to this post

    Hello shimmoril,

     

    I am happy to hear that you managed to fix the issue that you are having.

     

    And thanks for sharing!

     

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. Pavlos
    Pavlos avatar
    7 posts
    Member since:
    Dec 2014

    Posted 27 Oct 2015 Link to this post

    My appologies, I had submitted a ticket and it got solved there. 
    Like shimmoril suggested adding a model is what did the trick for me.

    I also added a Schema

    schema: {
                    data: "Data",
                    total: "Total"
    ....
    }

    Which solved it for me. Sorry for the late reply I lost track of this post.
    Thanks for following up though!

  8. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 27 Oct 2015 Link to this post

    Hello Pavlos,

     

    Great!

     

    In case you have any further questions, please do not hesitate to contact us.

     

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  9. Graham
    Graham avatar
    33 posts
    Member since:
    Jul 2012

    Posted 13 Sep 2016 in reply to Ashleigh L Link to this post

    To avoid this e.slice error I found that for a grid, my controller had to return as follows:

     

    Json(vehiclesList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)

     

    Whereas for a DropDownList, EXACTLY the same data had to be returned like this:

     

    Json(vehiclesList, JsonRequestBehavior.AllowGet)

  10. nitesh
    nitesh avatar
    3 posts
    Member since:
    Oct 2016

    Posted 01 Nov 2016 Link to this post

    while upgrading kendo.all.js (v2014.3.1411) to (v2016.3.914 ) then getting error e.option.tools.slice .Please help me for same and find attachments.

     

    Thanks

    Nitesh

  11. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 02 Nov 2016 Link to this post

    Hi,

    Would it be possible to extract a sample where the issue can be reproduced and send it in a separate ticket? We will be happy to help

    Regards,
    Kiril Nikolov
    Telerik by Progress
     
    Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
     
  12. Pascal
    Pascal avatar
    14 posts
    Member since:
    Mar 2016

    Posted 25 Nov 2016 in reply to Graham Link to this post

    Thanks Graham, you helped me solving the "e.slice is not a function" error on a combo box.
  13. Kevin
    Kevin avatar
    4 posts
    Member since:
    Dec 2015

    Posted 22 Jan in reply to Graham Link to this post

    Graham,

    Your solution helped me with the same issue. In my case I had a MobileListView that required .ToDataSourceResult(request), while the MultipleSelectList did not. I had both controls referencing the same function, and when I fixed it for one, it would break the other. Now I know why!

    Thanks!

  14. Zachary
    Zachary avatar
    3 posts
    Member since:
    Dec 2016

    Posted 01 Feb Link to this post

    Graham way to go, this resolved e.slice for me too.
  15. Steven
    Steven avatar
    5 posts
    Member since:
    May 2013

    Posted 02 Mar Link to this post

    Yeah Graham!

    Returning:

    return Json(result, JsonRequestBehavior.AllowGet);

    Instead of:

    return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

    Solved my issue.

  16. Shawn
    Shawn avatar
    3 posts
    Member since:
    Jun 2016

    Posted 15 May in reply to Graham Link to this post

    Graham's solution worked for me as well!
Back to Top