简体   繁体   English

TinyButStrong创造了动态 <th> 具有动态 <tr> 和 <td> 循环问题

[英]TinyButStrong created dynamic <th> with dynamic <tr> and <td> looping issue

I want to create the leave report of employee in calender table view as attached image. 我想在日历表视图中创建员工的休假报告作为附件图像。

在此处输入图片说明

i have fetched employee from controller and stored in and array. 我已经从控制器中获取了员工并存储在and数组中。
same way i am fetching the dates(based on selected year and month) in controller and stored in an array. 我以相同的方式在控制器中获取日期(基于选定的年份和月份)并存储在数组中。
based on this employee and date, i am fetching the leaves of each employee and stored in an array. 基于这个雇​​员和日期,我正在获取每个雇员的叶子并存储在数组中。

controller 调节器

    $month = 7;
    $year = 2015;
            for($d=1; $d<=31; $d++)//for dynamic dates as displayed in image
            {
                $time=mktime(12, 0, 0, $month, $d, $year);          
                if (date('m', $time)==$month)       
                $this->data['blk4'][]['date']=date('d', $time);
                $this->data['blk5'][]['day']=date('D', $time);
                $this->data['blk6'][]['fulldates']=date('Y-m-d',$time);
            }
            $data['employee'] = $this->teamprofile_model->allTeamMembers('team_profile_full_name', 'ASC');//fetching all amployee

            foreach($data['employee'] as $d)//for each employee checking the leave
            {
                foreach($this->data['blk6'] as $date)//for each date
                {   
                    $this->db->where('employee_id',$d['team_profile_id']);
                    $this->db->where('leave_date',$date['dates']);
                    $Q=$this->db->get('leave_reports');
                    if($Q->num_rows() > 0)
                    {
                        foreach ($Q->result_array() as $row)
                        {
                            $data1[] = $row;
                        }
                    }
                    $this->data['blk8'][]['leave'] = $data1[0]['leave_time'];//stored leave of each employee in this array
                    $data1="";
                }
            }

HTML HTML

<table class="footable table table-bordered table-hover" border="1">
      <thead>
             <tr>
                 <th>Employee</th>//display employee
                 <th><!--[blk4.date;block=th;comm]--><br/><!--[blk5.day;block=th;comm]--></th> //display dates as displying in above image
            </tr>
       </thead>
       <tbody class="">
            <tr>
                <td><!--[blk7.all_team_members;block=tr;comm]--></td>//dynamic employee list
                <td>here i want to display the leave stored in [blk8.leave]</td>                     
            </tr>
       </tbody>
</table>

but the problem is that the [blk8.leave] stored all employees leave of each dates so if i print it as [blk8.leave;block=td;comm] then it print all array value in one row. 但是问题是[blk8.leave]存储了每个日期的所有员工休假,所以如果我将其打印为[blk8.leave; block = td; comm],则它将所有数组值打印在一行中。 I want to break this array after month's end date that is 31. 我想在一个月的结束日期31之后打破这个数组。

在此处输入图片说明

output should be : 输出应为:

在此处输入图片说明

The problem is your Leave data is structured linearly while it need to be associated with a date. 问题在于您的请假数据需要与日期关联时才是线性结构。

TBS (TinyButStrong) as a built in feature for merging tables with dynamics columns (or other similar structure). TBS(TinyButStrong)作为内置功能,用于合并具有动力学列(或其他类似结构)的表。

The example under is very similar to your problem, you can adapt it easily. 下面的示例与您的问题非常相似,您可以轻松进行调整。 http://www.tinybutstrong.com/examples.php?e=dyncol1 http://www.tinybutstrong.com/examples.php?e=dyncol1

But the structure of your data should be amended. 但是您的数据结构应该修改。 Here is an example of how the data could be: 这是一个数据可能如何的示例:

        $blk7 = array();
        foreach($data['employee'] as $d)//for each employee checking the leave
        {
            $employee = array(
                'team_profile_id' => $d['team_profile_id'],
                'all_team_members' => $d['all_team_members'],
            );
            foreach($this->data['blk6'] as $date)//for each date
            {   
                $this->db->where('employee_id',$d['team_profile_id']);
                $this->db->where('leave_date',$date['dates']);
                $Q=$this->db->get('leave_reports');
                if($Q->num_rows() > 0)
                {
                    foreach ($Q->result_array() as $row)
                    {
                        $data1[] = $row;
                    }
                }
                $column = 'leave_' . $date['dates'];
                $employee[$column] = $data1[0]['leave_time'];//stored leave of each employee in this array
                $data1="";
            }
            $blk7[] = $employee;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM