2017-07-10 22 views
0

私の剣道グリッドでは、ポップアップエディタで編集した後、更新ボタンが機能しません。「結果」はAjaxコールレスポンスです。私はそれをコメントし、なぜだ "読み" の部分、更新されたデータをグリッドからコントローラに渡す方法

データソースの初期化:

dataSource = new kendo.data.DataSource({ 
    transport: { 
     //read: { 
      // url: result, 
      // dataType: "json" 
     //}, 
     update: { 
      url: "/AdminTool/update_grid", 
      dataType: "json" 
     },        
     parameterMap: function (options, operation) { 
      if (operation !== "read" && options.models) { 
       return { models: kendo.stringify(options.models) }; 
      } 
     } 
    }, 
    batch: true, 
    pageSize: 20, 
    schema: { 
     model: { 
      id: "DeviceIP", 
      fields: { 
       DeviceIP: { editable: false, nullable: true }, 
       Producer: { type: "string" }, 
       Model: { type: "string" }, 
       DeviceType: { type: "string" }, 
       Description: { type: "string" }, 
       Username: { type: "string" }, 
       Password: { type: "string" }, 
       PublicIP: { type: "string" }, 
      } 
     } 
    } 
}); 

剣道グリッド初期化:

$("#turbingrid").kendoGrid({ 
    dataSource: result, 
    scrollable: false, 
    columns: [ 
     { field: 'DeviceIP', title: 'DeviceIP', width: '100px', id: 'DeviceIP' }, 
     { field: 'Producer', title: 'Producer', width: '80px', editor: ProductNameDropDownEditor, }, 
     { field: 'Model', title: 'Model', width: '120px' }, 
     { field: 'DeviceType', title: 'DeviceType', width: '100px', editor:deviceTypesList }, 
     { field: 'Description', title: 'Description', width: '100px' }, 
     { field: 'Username', title: 'Username',width:'120px' }, 
     { field: 'Password', title: 'Password', width: '100px' },           
     { field: 'PublicIP', title: 'PublicIP', width: '120px' }, 
     { command: ["edit"], title: " ", width: "100px" }], 
     editable: "popup", 
     edit: function() { 
       document.getElementsByName("DeviceIP")[0].disabled = true; 
     },       
     editable: "popup" 
}); 

コラム編集:

function ProductNameDropDownEditor(container, options) {    
    $('<input name="Producer" data-type="string"\">') 
     .appendTo(container) 
     .kendoDropDownList({ 
      valuePrimitive: true, 
      dataSource: mydata, 
      dataTextField: "Text", 
      dataValueField: "Text", 
    });           
}    

function deviceTypesList(container, options) { 
    $('<input name="DeviceType" data-type="string" \">') 
     .appendTo(container) 
     .kendoDropDownList({ 
      dataSource: mydata_deviceType, 
      dataTextField: "Text", 
      dataValueField: "Text", 
      //dataValueField: "ProductName", 
    }); 
} 

マイコントローラー:

[HttpPost] 
    public ActionResult update_grid(TurbineDvce frm) 
    { 
     try 
     { 
      // TODO: Add update logic here 

      return RedirectToAction("Index"); 
     } 
     catch 
     { 
      return View(); 
     } 
    } 

私は何を指定する

public class TurbineDvce 
{ 
    public string TurbineId { get; set; } 
    public string DeviceIP { get; set; } 
    public string Producer { get; set; } 
    public string Model { get; set; } 
    public string DeviceType { get; set; } 
    public string Comments { get; set; } 
    public string Description { get; set; } 
    public string Username { get; set; } 
    public string Password { get; set; } 

    public string PublicIP { get; set; } 

} 
+0

少数のノートは、あなたがhttp://docs.telerik.com/kendo-ui/([ 'autoSync']を見てみたいことがあります。あなたの場合は

、一例は次のようになりますapi/javascript/data/datasource#configuration-autoSync)を使用して、変更が適用されるたびにサーバーを自動的に呼び出すことができます。あるいは、 'sync'を手動で呼び出すこともできます。オプションで、提供された 'transport.update'メソッドを使うか、あるいは' update'関数で[AJAX]を使うことができます(http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration- transport.update)。 – Sandman

+0

リクエストと共に送信される['data'](http://docs.telerik.com/kendo-u/api/javascript/data/datasource#configuration-transport.update.data)を指定することができます。または、オプションで['parameter.map'](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.parameterMap)を参照してください。 – Sandman

+0

@Sandmanありがとうございます。正直なところ、私はそれを別に書くか、私の剣道グリッドコードの間に入れなければならないか分かりません – mortezasol

答えて

0

使用parameterMap機能を渡したいモデル個々の剣道グリッド行を編集するときに、コントローラ機能に送るデータがあります。

操作内で、操作の種類に基づいてデータを返すさまざまな方法を指定することもできます。

transport: { 
    update: { 
     url:"/AdminTool/update_grid", 
     dataType: "json" 
    }, 
    parameterMap: function (data, operation) { 
     if(operation !== "read" && data) { 
      return kendo.stringify(data); 
     } 
    } 
} 
+0

にはcrudServiceBaseUrl + "/ Products"という部分がありますが、crudServiceBaseUrl(私のコントローラのURL)はわかりますが、2番目の部分(/ Product)は何ですか、私の2番目の質問は何ですか? ..?なぜ "読む"? – mortezasol

+0

上記の例のURL属性を、OPにあったURLを使用するために置き換えました。 ['read'](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read)は、剣道グリッドコントロールのデータをGETするための関数です。コントローラ。 'transport'設定に関する完全なドキュメントは、[here](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport)にあります。 – Sandman

+0

"うまくいかない"と言ったら、どういう意味ですか?あなたは質問を更新しましたが、現在の/予想される動作についての詳細は提供されませんでした。実行が 'parameterMap'関数に達して、コントローラ関数に問題がある可能性があることを示しますか?さらに、 'data'は' parameterMap'関数の中に何を含んでいますか?あなたのコントローラ機能は何を期待していますか?あなたの質問をコントローラ関数( 'update_grid')と期待するパラメータの構造体で更新してください。 – Sandman

関連する問題