2017-12-18 246 views
-1

我有一個項目數據表,我想在一行中插入一個日期選擇器。我有這個,但只顯示輸入沒有日期選擇器:在jQuery數據表中插入一個日期選擇器

"render": function(data, type, full, meta){ 
        var $tb = $("<input type='text' class='inlineevaldate' style='width:50px;'></input>"); 
        $tb.attr("id", "etxt" + full[0]); 
        $("#etxt" + full[0]).val(full[12]); 
        return $tb.prop("outerHTML"); 
       } 

我可以用這個更新日期:

initComplete : function(settings, json){ 
      $(".inlineevaldate").datepicker({ 
       changeMonth: true, 
       changeYear: true, 
       modal: false, 
       autoClose: true, 
       onSelect: function() { 
        $("#btnUpdateProject").focus(); 
        var whichrow = $(this); 
        var id = whichrow[0].id; 
        var val = whichrow[0].value; 
        var projectid = whichrow[0].id.substring(4); 
        $.ajax({ 
         type: 'POST', 
         data: { projectid : projectid, date : val }, 
         url: '@Url.Action("SetProjectEvalDate")', 
         success: function(data){ 
          if (data === "ERROR") { 
           ErrorDialog("#MessageDialog", "#lblError", "The was an error encountered, please try again later.", "Error"); 
           return false; 
          } 
         } 
        }); 
       } 
      }); 

但我不能設置輸入的初始值。有任何想法嗎?

+1

'textbox'不'textarea'? – bassxzero

+0

@bassxzero只是一個文本框,就像我通常在創建日期選擇器時所做的一樣。 –

+0

您可能需要在回調中調用'$('。datepicker')。datepicker();'...?也許你正在嘗試一個JSFiddle ......? – annoyingmouse

回答

0

我渲染此列:

"render": function(data, type, full, meta){ 
        var $tb = $("<input type='text' class='inlineevaldate' value='" + full[12] + "' style='width:50px;'></input>"); 
        $tb.attr("id", "etxt" + full[0]); 
        return $tb.prop("outerHTML"); 
       } 

,然後配置日期選擇器表後初始化:

initComplete : function(settings, json){ 
      $(".inlineevaldate").datepicker({ 
       changeMonth: true, 
       changeYear: true, 
       modal: false, 
       autoClose: true, 
       onSelect: function() { 
        $("#btnUpdateProject").focus(); 
        var whichrow = $(this); 
        var id = whichrow[0].id; 
        var val = whichrow[0].value; 
        var projectid = whichrow[0].id.substring(4); 
        $.ajax({ 
         type: 'POST', 
         data: { projectid : projectid, date : val }, 
         url: '@Url.Action("SetProjectEvalDate")', 
         success: function(data){ 
          if (data === "ERROR") { 
           ErrorDialog("#MessageDialog", "#lblError", "The was an error encountered, please try again later.", "Error"); 
           return false; 
          } 
         } 
        }); 
       } 
      }); 
相關問題