【解決方法】dhtmlx ガント チャートで動的データ バインドする方法

プログラミングQA

[ad_1]

DHTMLXガントチャートで動的データバインドする方法

動的データの場合は for ループを使用します

私が試したこと:

//for (var i = 0; i < 5; i++)
                   //{
                   //    data.push({
                   //        "data" :  { "id": 1, "text": "Strand Pickling", "Job": "3.1.9", "ONumber": "1", "Itm": "0.89 MM NT BW", "Qty": "50", "start_date": "28-03-2017", "end_date": "01-04-2017 21:00:00", "ItemName": "2", "duration": "3", "progress": 0.2, "open": true },
                   //    })
                   //}

解決策 1

foreach (DataRow dr in dt.Rows)
           {
               if (buffer == string.Empty || buffer != dr["SectionName"].ToString())
               {
                   parent = 0;
                   ProSchedular.Add(new Production(i + 4, dr["SectionName"].ToString(),emptydata,emptydata,emptydata,emptydata, dr["sdate"].ToString(),
                                                       dr["edate"].ToString(), parent));
                   parent = i + 4;

                   ProSchedular.Add(new Production(i + 5, dr["machines"].ToString(), dr["JobNo"].ToString(), dr["OrderNumber"].ToString(), dr["ItemName"].ToString(),
                                  dr["ProductionQuantity"].ToString(), dr["sdate"].ToString(), dr["edate"].ToString(),parent));

                   buffer = dr["SectionName"].ToString();
               }
               else
                   ProSchedular.Add(new Production(i + 6, dr["machines"].ToString(), dr["JobNo"].ToString(), dr["OrderNumber"].ToString(), dr["ItemName"].ToString(),
                                 dr["ProductionQuantity"].ToString(), dr["sdate"].ToString(), dr["edate"].ToString(), parent));

               i = i + 7;
           }


           return ProSchedular;
       }
       catch (Exception ex)
       {
           logwriter.Debug(ex.Message.ToString());
           //objMas.PrintLog(" Pageid : " + pageid + " First Time page load  Fetch Details From CardMaster : ",ex.Message.ToString());
           return ProSchedular;
       }

   }
     public class Production//pagedetail
     {
         public int id = 0;
         public string start_date = "", end_date = "", text = "", Job = "", ONumber = "", Itm = "", Qty = "";
         public int parent;
         public bool open;
         public string buffer = "";

         public Production(int  i,string section,string jobNumber,string OrdNum,string Item ,string qty,string SDate, string EDate,int p)
         {
             if (buffer == string.Empty || buffer != section)
             {
                 id = i; text = section; Job = jobNumber; ONumber = OrdNum; Itm = Item; Qty = qty; start_date = SDate; end_date = EDate;open = true;
                 parent = p;buffer = section;
             }
             else
             {
                 id = i; text = section; Job = jobNumber; ONumber = OrdNum; Itm = Item; Qty = qty; start_date = SDate; end_date = EDate; open = true;
                 parent = p;
             }
         }
     }

解決策 2

私も同じ状況になりました。コードを助けてください。

<script>
        var objData;
        var objLinks;
        $(document).ready(function () {
             gantt.init("gantt_chart");
             loadData();
        });

        function loadData() {
            var url1 = jQuery("#hidAppPath").val() + "/service/postData.aspx?requestType=bindactivityforgantt";
            $.ajax({
                type: "GET",
                url: url1,
                data: '',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {

                    console.log(response[0]);
                    objData = response[0].data;
                    objLinks = response[0].links;

                    console.log(objData);
                    console.log(objLinks);

                    var dataStr = '';
                    dataStr = dataStr + 'gantt.parse({data:[';

                    $.each(objData, function (i, val) {
                        dataStr = dataStr + '{ "id": ' + val.id + ', "text": "' + val.text + '", "start_date": "' + val.start_date + '", "duration": ' + val.duration + ', "progress": ' + val.progress + ', "open": ' + val.open + ' },';
                    });
                    dataStr = dataStr.trimEnd(",");
                    dataStr = dataStr + ']});';
                    console.log(dataStr);
                    return dataStr;

                },
                error: function (errorRespon) { }
            });
        }

        

    </script>

[ad_2]

コメント

タイトルとURLをコピーしました