Kendo寻呼机不会重置回第一页

时间:2016-11-01 18:35:13

标签: kendo-ui

我有一个kendo数据源,它可以调用我的api,我只限制了10页。我的问题是寻呼机不会回到第一页。例如,当我打电话和我的api并收到50个结果时,我将有5页,每页10个项目。我选择转到第五页,然后我再拨打一个电话,只收到10个项目。然而,校准完成我仍然在第5页;它不会重置为第一页。

    var dataSource = new kendo.data.DataSource({
    page:1, << From what I read this is suppose to do the job
    pageSize: 10,
    transport: {
        read: {
            type: "POST",
            url: location + "/api/ContentSearch/SearchRequest",
            contentType: 'application/json',
            beforeSend: function (req) {
                req.setRequestHeader("Authorization", "Bearer " + token);
            }
        },
        parameterMap: function (option, operation) {
            return JSON.stringify(query);
        }
    },
    change: function (e) {
        var data = this.data();
        $("#searchButton").prop("disabled", false);
        $("#loadingGif").hide();
        //kendoPager.page(1); << does not work
        switch (data.length) {
            case 0:
                FeedBackMessage("No result found");
                break;
            case 500:
                FeedBackMessage("Please check or refine the search");
                break;
            default:
                $('#pager').show();
                $('#descriptionColumn').show();
                $("#listView").show();
                $("#keyWordText").val("").data("kendoDropDownList").text("");
                $("#searchText").val("");

        }
        return data;
    },
    error: function (e) {
        $("#loadingGif").hide();
        ErrorHandler(e.sender.transport.options.read.url, e.xhr.status, e.xhr.statusText, "Kendo datasource was not binded to the WebApi response", "", true);           
    }
});

 function SubmitSearch(e) {
    e.preventDefault();

    query = {
        SearchText: $("#searchText").val(),
        KeywordText: generalContentKeywords.text(),
        GlobalSearch: true
    };
    if (query.SearchText === "" && query.KeywordText === "Select Category") {
        FeedBackMessage("Please enter a value");
    }
    else {
        if (query.KeywordText === "Select Category") {
            query.KeywordText = "";
        }
        $.when(TokenForWebApi()).then(function (adalToken) {

            token = adalToken;
            $('#pager').hide();
            $('#descriptionColumn').hide();
            $("#listView").hide();
            $("#searchButton").prop("disabled", true);
            $("#loadingGif").show();
            dataSource.read();
        });


    }
};

var kendoPager = $("#pager").kendoPager({
    dataSource: dataSource,
}).data("kendoPager");

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,通过更改我的提交函数来查看数据源是否有任何数据,如果它发现它重置,则重置将页面设置为1。我猜我以前的代码,我试图在数据源有任何页面值之前设置一个页面值。

   function SubmitSearch(e) {
    e.preventDefault();
    query = {
        SearchText: $("#searchText").val(),
        KeywordText: generalContentKeywords.text(),
        GlobalSearch: true
    };
    if (query.SearchText === "" && query.KeywordText === "Select Category") {
        FeedBackMessage("Please enter a value");
    }
    else {
        if (query.KeywordText === "Select Category") {
            query.KeywordText = "";
        }
        $.when(TokenForWebApi()).then(function (adalToken) {
            if (dataSource._pristineData.length) {
                kendoPager.page(1);
            }
            token = adalToken;
            $('#pager').hide();
            $('#descriptionColumn').hide();
            $("#listView").hide();
            $("#searchButton").prop("disabled", true);
            $("#loadingGif").show();
            dataSource.read();
        });
    }
};