MVC+easyui-datagrid之查看詳情

來源:互聯網
上載者:User

標籤:mvc+easyui-datagrid之

          在做GXPT時,我負責課表這塊兒,而這塊兒最大的特點是很難用到大家公用的東西,只能自己一點點去做,其中之一就是查看詳情,這個功能我做了大概有兩天時間,下面是我做的成果:

          

         點擊查看詳情後,要彈出對應ID 的內容,如下:

           

          下面看一下這個功能的具體實現:

            先看View:           

<span style="font-size:14px;"><table id="dgTimeTable" class="easyui-datagrid" style="position: relative;height:auto;" data-options="url:'/BasicTimeTable/QueryTimeTable/',checkbox:true,resizable:true,collapsible:true,method:'get',autoColWidth:true,pageSize:10,rownumbers:true,pagination:'true',fitColumns:true">                <thead>                    <tr>                        <th data-options="field:'ck',checkbox:true"></th>                        <th data-options="field:'TimeTableID',hidden:true">課表ID</th>                        <th data-options="field:'OnClassName',hidden:true">上課班名稱</th>                        <th data-options="field:'CourseName'">課程名稱</th>                        <th data-options="field:'Cycle'">周期</th>                        @*<th data-options="field:'weekly',width:100">周次</th>*@                        <th data-options="field:'StratWeek'">開始周</th>                        <th data-options="field:'EndWeek'">結束周</th>                        <th data-options="field:'StartSectionName'">開始節次</th>                        <th data-options="field:'EndSectionName'">結束節次</th>                        <th data-options="field:'Week'">星期</th>                        <th data-options="field:'BuildingName'">建築</th>                        <th data-options="field:'RoomName'">教室</th>                        <th data-options="field:'OnClassNamey',<strong><span style="color:#ff0000;">formatter: rowformater</span></strong>">上課班資訊</th>                        <th data-options="field:'operation',formatter:formatOper,hidden:true">操作</th>                        <th data-options="field:'TeacherName',hidden:true">授課教師</th>                        <th data-options="field:'courseID',hidden:true">課程ID</th>                        <th data-options="field:'CourseType',hidden:true">課程類型</th>                        <th data-options="field:'CourseProperty',hidden:true">課程性質</th>                        <th data-options="field:'Semeter',hidden:true">學年學期</th>                        <th data-options="field:'Period',hidden:true">學時</th>                        <th data-options="field:'Credit',hidden:true">學分</th>                        <th data-options="field:'Totalmember',hidden:true">                        人數</th>                         <th data-options="field:'StudentNo',hidden:true">                        學號</th>                        <th data-options="field:'Name',hidden:true">姓名</th>                           <th data-options="field:'ClassName',hidden:true">班級</th>                          <th data-options="field:'GradeName',hidden:true">年級</th>               <th data-options="field:'Profession',hidden:true">專業</th>               <th data-options="field:'pProfession',hidden:true">學院</th>                                            </tr>                </thead>            </table>        </div>    </div></div></span>
               加紅處就是我要處理的“查看詳情”的地方,下面再JS中給這個欄位附上事件:

              

<span style="font-size:14px;"><script type="text/javascript">    //查看詳情介面    function <strong>showDialog</strong>(aa, courseName, courseType, teacherName, semeter, period, credit, totalmember, organization, timetableid) {        //document.getElementById("courseID").innerText = courseid;        document.getElementById("CourseProperty").innerText = aa;        document.getElementById("CourseName").innerText = courseName;        document.getElementById("CourseType").innerText = courseType;        document.getElementById("TeacherName").innerText = teacherName;        document.getElementById("semeter").innerText = semeter;        document.getElementById("Period").innerText = period;        document.getElementById("Credit").innerText = credit;        document.getElementById("Totalmember").innerText = '45';        document.getElementById("Organization").innerText = organization;        document.getElementById("TimeTableID").value = timetableid;        $('#dlgOnClassDetail').dialog('open').dialog('setTitle', '上課班資訊');    }    //查看詳情超連結    function rowformater(value, row, index) {        return "<a  href='#' onclick='<strong><span style="color:#ff0000;">showDialog</span></strong>(" + '" ' + row.CoursepropertyName + '"' + "," + '" ' + row.CourseName + '"' + "," + '" ' + row.CourseTypeName + '"' + "," + '"' + row.teacherName + '"' + "," + '" ' + row.Semeter + '"' + "," + '" ' + row.Period + '"' + "," + '" ' + row.Credit + '"' + "," + '" ' + row.TotalMember + '"' + "," + '" ' + row.OrganizationName + '"' + "," + '"' + row.TimeTableID + '"' + ")'>查看詳情</a>";    } </script></span>
            下面是controller中的內容:
<span style="font-size:14px;"> public ActionResult QueryTimeTable(string strLike)        {            int pageSize = Request["rows"] == null ? 10 : int.Parse(Request["rows"]);            int pageIndex = Request["page"] == null ? 1 : int.Parse(Request["page"]);            int total;            List<TimeTable> timetableList = new List<TimeTable>();            //strLike = Request.Form["strLike"];            if (strLike == "" || strLike == null)            {                timetableList = iBasicTimeTable.QueryTimeTable(pageSize, pageIndex, out total);            }            else            {                timetableList = iBasicTimeTable.FuzzyQueryTimeTable(strLike);//查詢到匹配的list            }            //將list轉換成json字串,需要序列化            JavaScriptSerializer servializer = new JavaScriptSerializer();//執行個體化一個序列化對象            string strTimeTableJson = servializer.Serialize(timetableList);            var data = new            {                //total,                rows = timetableList            };            return Json(data, JsonRequestBehavior.AllowGet);        }</span>
              在我的需求中用到了對多個表的操作,包括節次、上課班、課程、教師、學生、建築,所以說在底層,也就是WCF中的實現,難度也大大加大,因為返回的介面的內容很多,包括很多的表,所以,下面來看看我底層的實現:底層用的是三層+WCF+ViewModel+EF             

<span style="font-size:14px;"> public List<TimeTable> QueryTimeTable(int pageSize, int pageIndex, out int total)        {   //執行個體化一個資料泛型集合            List<TimeTable> timetablelist = new List<TimeTable>();            //調用BLL層介面            var result = IBasicTimeTable.LoadPageItems(pageSize, pageIndex, out total, p => p.TimeTableID, true);            //使用迴圈,遍曆IQuerble集合,賦值到資料契約            foreach (var item in result)            {                List<Student> studentlist = new List<Student>();                //構造器                //var onclassstudentlist = IBasicOnClass.LoadEnities(n => n.OnClassID == item.OnClassID).ToList();                var onclassstudentlist = IBasicOnClassStudent.LoadEnities(n => n.OnClassID == item.OnClassID).ToList();                foreach (var studentTmp in onclassstudentlist)                {                    Student student = new Student                    {                        StudentID = studentTmp.StudentID,                        StudentNo = studentTmp.BasicStudentEntity.StudentNo,                        Name = studentTmp.BasicStudentEntity.Name,                        ClassName = studentTmp.BasicStudentEntity.BasicClassEntity.ClassName ,                        GradeName = studentTmp.BasicStudentEntity.BasicClassEntity.BasicGradeEntity.GradeName,                        TrainDestination = studentTmp.BasicStudentEntity.TrainDestination,                        OrganizationName = studentTmp.BasicStudentEntity.BasicClassEntity.BasicOrganizationEntity.OrganizationName //學院                    };                    studentlist.Add(student);                }                TimeTable timetable = new TimeTable                {                    TimeTableID = item.TimeTableID,                    OnClassName=item.BasicOnClassEntity.OnClassName,                    EndWeek = item.EndWeek,                    StratWeek = item.StratWeek,                    Cycle = item.Cycle,                    OnClassID = item.BasicOnClassEntity.OnClassID,                    CourseName = item.BasicOnClassEntity.BasicCourseEntity.CourseName,                    StartSectionName = item.BasicSectionEntity.SectionName,                    EndSectionName = item.BasicSectionEntity1.SectionName,                    Week = item.Week,                    BuildingName = item.BasicRoomEntity.BasicBuildingEntity.BuildingName,                    RoomName = item.BasicRoomEntity.RoomName,                    CourseTypeName = item.BasicOnClassEntity.BasicCourseEntity.BasicCourseTypeEntity.CourseTypeName,                    CoursepropertyName = item.BasicOnClassEntity.BasicCourseEntity.BasicCoursepropertyEntity.CoursepropertyName,                    OrganizationName = item.BasicOnClassEntity.BasicCourseEntity.BasicOrganizationEntity.OrganizationName,                    teacherName = item.BasicOnClassEntity.BasicTeacherEntity.Name,                    SchoolYear = item.BasicOnClassEntity.BasicSchoolCalendarEntity.SchoolYear,                    Term=item.BasicOnClassEntity.BasicSchoolCalendarEntity.Term,                    Period = item.BasicOnClassEntity.BasicCourseEntity.Period,                    Credit = item.BasicOnClassEntity.BasicCourseEntity.Credit,                    studentSum = item.BasicOnClassEntity.TotalMember,                    studentList = studentlist                };                timetablelist.Add(timetable);            }            return timetablelist;        }</span>
             代碼的實現到此為止,可是其中的思路和遇到問題時的心態回想起來比敲代碼更加重要,因為查看詳情這個問題在一開始做的時候確實沒有頭緒, 查完資料,看完前輩們的之後,然後會感覺無從下手,於是一開始的時候就會有些焦慮,消極,但是現在想想,一切的焦慮、心煩只能是為自己的問題火上焦油,根本起不到任何好的作用,還有就是在遇到問題時,用工具的技巧、意識的培養都很重要,當我讓其他的同學來幫我調的時候,我發現自己欠缺的更多的是工具的提示,所以說用好工具可以助自己一臂之力啊!


      

MVC+easyui-datagrid之查看詳情

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.