1. Requirements.
1. Add a drop-down box to do the query
2. New check box in front of the list click to get the corresponding ID of the row corresponding to the sum of the data (click the second cumulative), you can select all
2. Part of the code operation area:
<table> <tr> <td> Batches: <select id= "Batch" > @foreach (var item in Model.batchlist) { <option value= "@item" > @item </option> } </select> < Input id= "resumebt" value= "Query" type= "button"/> The total amount of data for the query is: <label id= "Resumecount" > @Model .total</label> </td> </tr> <tr><td> The number of downloads for the selected row is: <label id= "Resumedownnum" ></ Label> times, viewed: <label id= "Resumebrowsenum" ></label> times </td></tr> </table>
Js:
<script> $ (function () {$ ("#batch"). Val ("@Model. Batch"); $ ("#ResumeBt"). Click (function () {window.location = "/resume/resumestatistics?batch=" + $ ("#batch"). Val (); }); About check box var inum = 0;//used to Count $ ("#ResumeCheckedAll"). Click (function () { inum++; if (inum% 2 = = 1) {$ ("input[type= ' checkbox ']"). Prop ("checked", true);//Select All $.post ("/resume/getresumenumall", {"Batch": $ ("#batch"). Val ()},function (data) {if (data = = "Error") {alert ("The Logged Batch information (batch) is empty, please check the procedure for errors!") "); Return } console.info (data); $ ("#ResumeDownNum"). html (data[0]. Downloadnum); $ ("#ResumeBrowsenum "). html (data[0]. Browsenum); }, "JSON"); } else {$ ("input[type= ' checkbox ']"). Prop ("checked", false);//Select All $ ("#R Esumedownnum "). HTML (0); $ ("#ResumeBrowseNum"). HTML (0); } }); }); var resumedownnumcount = 0;//Record the total number of downloads for the selected row var resumebrowsenumcount = 0;//Records the total number of views of the selected row function Res umechecked (obj) {$.post ("/resume/getresumenum", {"id": obj},function (data) {if (data = = "Error") {alert ("the number (ID) of the record is empty, please check if the procedure is wrong!") "); Return } console.info (data); Determine if the IF ($ ("#") is checked for each cumulative time ("+obj"). Is (": Checked")) {Resumedownnumcount =resum Edownnumcount + data[0]. Downloadnum; ResumeBrowsenumcount =resumebrowsenumcount + data[0]. Browsenum; } else {Resumedownnumcount =resumedownnumcount-data[0]. Downloadnum; Resumebrowsenumcount =resumebrowsenumcount-data[0]. Browsenum; } $ ("#ResumeDownNum"). HTML (resumedownnumcount); $ ("#ResumeBrowseNum"). HTML (resumebrowsenumcount); }, "JSON"); } </script>
Controller:
Public ActionResult resumestatistics (int pageIndex = 1) {String batch = request["Batch"]; var model = new Resumestatisticslistmodel (); Model. Batchlist = _resumestatisticsbll.option (); for (int i=0;i< model. batchlist.count;i++) {model. Batchlist[i] = model. Batchlist[i]. Trim (); }//Set size per page int pageSize = 15; Total number of queries//If there is a condition, the total of int = 0 is checked according to the conditions; Filter data by batch when passing parameters if (batch! = null && pageindex!=0) {total = _resumesta Tisticsbll.getbatchcount (Batch); Model. Items = _resumestatisticsbll.getbatchall (pageSize, Pageindex,batch); Model. Total = total; Model. batch = batch; Model. Pages = Pagehelper.getpagelist (PageIndex, PageSize, Total, "/resume/resumestatistics?pageindex={0}&batch=" + Batch); return View (model); } else {total = _resumestatisticsbll.getcount (); Model. Items = _resumestatisticsbll.getall (pageSize, PageIndex); Model. Total = total; Model. batch = batch; Model. Pages = Pagehelper.getpagelist (PageIndex, PageSize, Total, "/resume/resumestatistics?pageindex={0}&batch=" + Batch); return View (model); } }
3. Problems encountered and solutions
@1. Cannot get the check box for the corresponding ID and cannot do the corresponding action = "Because the VS auto-recognition error impact judgment and the reference JS script limit the attributes
Solution: (vs Smart tips do not say, do not know why there is a hint of exception, but the code can still run, which is a bit fraught), found a reference to the script, in a look sure enough, the checked attribute is limited to select only one box, the code after the ban can be more select, And it's not the same factor that's going to come out.
@2. Conditional query and paging in the address bar conflict = "The reason is that all two are implemented with the address bar in the parameters to achieve their respective effects (eg:window.location ="/resume/resumestatistics?batch= "+ $ (" # Batch "). val (); & (due to halfway decent, modeled is not one person)
Solution: At that time there is a two plan, @1. One of the other ways to implement (that is, only one with the address bar to jump) @2. Change the page address bar configuration, set some other properties, and so on (processing drop-down boxes). It has to be said that because other people do the pagination and their imagination is not quite the same, initially seems to be not very good to change, more inclined to use other ways to implement the query, but there is no better idea (here to borrow other modules query implementation, a line of code to solve the problem), so the eyes have shifted to the paging. Have to say, feel to feel, or see how others are to achieve pagination, with a number of HTML helper methods (for not how this do I am a bit unaccustomed), to find the source and nature, and then changed the change, with a parameter, and then came out. I do not know whether it is lucky or a bit of a foundation, or, it is not difficult.
@2. The page effect is a bug = "The reason is that I do the query is to replace the original data, paging based on the query nature will be associated, but at first did not realize the problem
Resolution: Select Batch click on the second page when the data is empty, obviously, here do a fake paging. After detection, because in the address bar to pass the value of the time in an else with more batch (in fact, else inside is not with, because the value is "" "empty string is not present in this condition of the data)
@3. Page JS because commented out the public code block (have to say that this is almost fatal, the other reference to the JS code will have a great impact) = "The reason is that they think too simple always think it!"
Workaround: Do not reference the conflicting JS script file, only reference the script with the style, and the way of reference is to call the function to pass parameters in. Eg:settrcolor ("userlisttable");//Load Table style
@4. After adding the Show All button, select all to select all batches of the total information "amount", (here in the data access layer is not to make a judgment) = "This problem changed
Say something else, not a particularly big problem, but affect the user experience, add display all the information is also the guidance of my people and I said (honestly do not realize this, programmers still have to consider the user experience, not just the old code, need to understand or want to clear. Admittedly, a "master" can take this experience is very good, although inevitably scold. But I try to do it well, experience is such accumulation, but this period of time may be hard for him = =)
PS: The whole function did two days, the first day to learn some basic information, mainly familiar with this module, for the next day to skillfully modify the code to do some basic preparation! Of course also wrote some code, according to my speed and progress, is to do a drop-down box loading and query, the basic SQL written out, the interface write half, also left some bugs (technical problems, not lazy, so go back to think about, today do more smoothly, A lot of small details yesterday suddenly out of the day, and soon, so sometimes walk on the road or sleep when you think of things to do during the day or very effective, whether out or not come out). In general, doing these things, although not well thought out, has been criticized, but the harvest is still very big! Compared to the daily throw resume or change some front-end code, I think the backstage or more suitable for me, even if I now do something very simple in the eyes of others may be insignificant, but I would like to say. My strong point is not that I learned a lot of things at school, I think more is step by step it! Think more, become a master only time left. Growing up on the road without questioning and ridicule, habits are good.
Background management, to add query function to the list page, the problems and feelings encountered