2016-10-24 3 views
0

".xlsx"파일로 다운로드 할 수있는 검도 그리드를 만드는 함수가 있습니다. 드롭 다운 메뉴가 변경되면이 기능이 다시 호출됩니다. 내가 파일을 다운로드 버튼을 클릭하면"Export to excel"버튼 kendogrid는 1 개 이상의 파일을 다운로드합니다.

function CreateGrid(result) { 

    var chartSeries = result.ChartData; 
    var gName = $("#dropdown1 option:selected").text(); 
    // Create Grid 
    $("#grid1").kendoGrid({ 
     toolbar: ["excel"], 
     excel: { 
      fileName: "Grid1_"+gName+".xlsx", 
      filterable: true, 
      allPages: true 
     }, 
     columns: [ 
      { field: "column1", width: "90px", title: "<strong>Item1</strong>" }, 
      { field: "column2", width: "80px", title: "<strong>Item2</strong>" }, 
      { field: "column3", width: "120px", title: "<strong>Item3</strong>", format: "{0:c2}" } 

     ], 
     groupable: false, 
     resizable: true, 
     pageable: false, 
     scrollable: true, 
     filterable: false, 
     sortable: true, 
     pageSize: 50 
    }); 

    // Set Grid data source 
    $("#grid1").data("kendoGrid").setDataSource(
     new kendo.data.DataSource({ 
      //Set the data of the grid as the result array of object. 
      data: result.ChartData 
     }) 
    ); 
} 

문제는이다, 내가는 현재 하나를 할 때 이전에 만든 모든 그리드를 다운로드합니다. 예를 들어 그리드를 한 번 만든 다음 드롭 다운을 변경하고 그리드가 새 드롭 다운 값에 해당하는 값으로 변경되었지만 버튼을 클릭하면 첫 번째 그리드에서 두 개의 파일을 다운로드하고 전시. 드롭 다운을 다시 변경하면 드롭 다운 값에 따라 값이 변경되지만 파일을 다운로드하려면 클릭하면 이전의 2 개의 파일 + 그리드에있는 하나의 파일이 다운로드됩니다.

더 이상 이전 격자를 볼 수 없다고 생각하는 것처럼 보이지만 여전히 거기에있어 내가 어떻게 그들을 파괴/지우기/청소 할 수 있는지 알고 싶습니다.

답변

1

새 표를 만들기 전에 표를 제거하는 것이 좋습니다. 이 기능을 삭제 것이며, 당신이하려는 경우 또한, 그리드 당신에게 현재의 데이터를 반환를 다시 할당합니다

다음
function removeGrid(g) { 
    var tmp = []; 
    try { 
     tmp = g.data("kendoGrid").dataSource.data(); 
    } catch (e) { } 
    var container = g.parent(); 
    g.remove(); 
    container.append("<div id='" + g.attr("id") + "' class='" + g.attr("class") + "'></div>"); 
    return tmp; 
} 

이처럼 호출 할 수 있습니다

var gName = $("#dropdown1 option:selected").text(); 
removeGrid($("#grid1")); 
// Create Grid 
$("#grid1").kendoGrid({ 
    ... 
}