This is a migrated thread and some comments may be shown as answers.

select grid data except the column with edit button

7 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lienys
Top achievements
Rank 2
Lienys asked on 14 Mar 2014, 06:54 PM
How can I do:

var allData = $("#grid").data("kendoGrid").dataSource.data();

allData = allData.column(-1); ==> this delete the last column..

7 Answers, 1 is accepted

Sort by
0
Lienys
Top achievements
Rank 2
answered on 14 Mar 2014, 07:04 PM
How can I get the grid data except the Command column that I add?
0
Dimiter Madjarov
Telerik team
answered on 17 Mar 2014, 09:31 AM
Hello Lienys,


I am not sure that I understand the current question. The data() method of the dataSource returns all of the data items in the Grid with all their model properties, not just the ones that are bound to any column. You could also use the view() method of the dataSource to get them with the according paging, filtering, grouping etc. applied.

Please let me know if this is the required behavior or I could assist you further.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Lienys
Top achievements
Rank 2
answered on 17 Mar 2014, 02:14 PM
My problem is:

I am exporting the grid data to excel, and when I create an edit/destroy page I bound an edit/destroy column, which is perfect for functionality, but when I want to export, the edit/destroy column appears in my data() and when I try to export to Excel I'm not expecting this extra column without header.

what I need is the grid data according to my model and not with the extra column.

how can I get that information?

thanks in advance
0
Dimiter Madjarov
Telerik team
answered on 17 Mar 2014, 04:34 PM
Hello Lienys,


As stated in my previous post, the data() method of the dataSource returns the items according to the model. The dataSource is not aware of the commands, being used in the Grid.

If the problem is still persisting, could you please share a sample project, demonstrating the current scenario and the exact problem, so I could assist further if needed?


Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Lienys
Top achievements
Rank 2
answered on 17 Mar 2014, 09:52 PM
I will give you some photos and code, you will see the difference between the two grids are the command-column.

my.js
        // export to excel
        $("#toExcel").click(function ()
        {
            var title = getCurrentViewName();

            var dg = $("#grid").data("kendoGrid");

            var gridData = getFilteredData(); 

            var data = {
                grid: JSON.stringify(gridData),
                columns: JSON.stringify(dg.columns),
                title: title
            };

            //Create the spreadsheet.
            $.ajax({
                type: "POST",
                url: "/ClientFunction/ExportToExcel",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify(data)
            })
            .done(function (e) {
                // Download the spreadsheet.
                window.location = kendo.format("{0}?title={1}",
                    "/ClientFunction/GetExcelFile",
                    title);
            });

        });

function getFilteredData()
{
    var ds = $("#grid").data("kendoGrid").dataSource;

    var filters = ds.filter();

    var allData = ds.data();

    var query = new kendo.data.Query(allData);

    var gridData = query.filter(filters).data;

    return gridData;
}

I'm using the excel.cs from:
http://blogs.telerik.com/kendoui/posts/13-03-12/exporting_the_kendo_ui_grid_data_to_excel
which I downloaded from:
https://github.com/telerik/kendo-examples-asp-net-mvc/tree/master/grid-export-to-excel
0
Accepted
Dimiter Madjarov
Telerik team
answered on 18 Mar 2014, 01:21 PM
Hi Lienys,


This behavior is expected in the current case. The columns object of the Grid is sent to the controller, where the title property of each column is used to generate the title of each column in the spreadsheet. As the exception explicitly states, the command column does not have a title. As a solution you could splice only the columns that are required for the spreadsheet generation.
E.g.
//assuming that the last column is not needed
 JSON.stringify(dg.columns.splice(0, dg.columns.length - 1))

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Lienys
Top achievements
Rank 2
answered on 18 Mar 2014, 03:35 PM
Thank you so much! it work!!!
Tags
Grid
Asked by
Lienys
Top achievements
Rank 2
Answers by
Lienys
Top achievements
Rank 2
Dimiter Madjarov
Telerik team
Share this question
or