I'm going to simplify this question.
I have a jqgrid instance which posts an array of ids to the server. I would like the pass in a new list when an event is triggered. Instead of overwriting the old list, jqgrid will add to it. How can i set the post parameters to create a new list each time I reload the grid.
This is the code to reload the grid with new post data
$('#gridConfirm').jqGrid('setGridParam',{postData:{'deviceIDs':$("#device").val()}});
$('#gridConfirm').trigger('reloadGrid');
I've confirmed that $("#device").val() returns a list of id's in the form "5,6,7,8"; So i'm expecting this list to be posted to the server.
Instead, its posting "5,6,7,8" plus the previous list. so if the previous list was "1,2,3,4". It's posting "5,6,7,8,1,2,3,4"
How can i clear the previous posted list when reloading the grid?
*edit*
On slight correction, when i change my postdata list. It does not append it overwrites, but it keeps the length of the list.
so if my original list was 1,2,3,4,5 and i selected 6,7 my new list is 6,7,3,4,5
I'm thinking this is a bug in the grid.
Now you removed all code from your question. So I wrote the demo myself which has no problem which you described. You can look at the source and compare with your version to see where you have a problem. In any way I would recommend to use postData having functions as properties (see here).
Related
I have a dgrid with inputs. My dgrid is in edit mode so users can add rows, edit rows and sort rows. When I look at my collection, it looks like
id: "1"
COLUMN1: "INPUT TYPE="text"...."
COLUMN2: "INPUT TYPE="text"...."
Note: I could not put the greater than and less than above with describing the inputs.
and so on. When I make a change on screen, for one of the inputs, the collection is not updated. So, when I enter a new row or sort the dgrid, all the entered data refreshes back to its original state. I know the reason is because the collection is not updated. Is it possible to update the collection or do I have to write my own code to do so? Please note, I am using a dgrid and NOT an onDemand grid.
Thanks for your help in advance.
Please add some code on how you are initializing your collection and what all mixins are being used for it. As far as I can understand your problem, you need to add the Trackable mixin in your collection. Read its documentation here.
From the documentation:
We can add support for tracking the position of updates by using the Trackable mixin. With the Trackable mixin added to a store, we can call the store's track method to get a collection that includes index information in its delete, add, and update events.
This might be of your help.
We have a split app with sorting feature for the list in masterview. The sort happens properly. But when any submit action is triggered in detailview, the masterview is refreshed to remove the submitted listitem and the sorting is lost.
How do I retain the sorting? Is there a property I could refer to retain the sorting? I tried to store the sort key and sort order in sessionStorage and read it before refreshing the model and re-sort the returned data in array before assigning it to model.
I am pretty new to UI5, any help will be highly appreciated.
Thanks
This would be case if you are sorting via controller once the data is loaded.
You can either:
Add the sorter to the list in the view OR
Add sorter at model level
OR
After refresh apply the same sorting which you used to before.
PS:I can add coding context if you can add your code in the question
How to hide specific rows in Handsontable.
I have buttons in DOM, each of them should hide specific rows.
For example: click button with class `alarm' should shide all rows which second column has value 'alarm'.
For now i do ugly thing. Every button click i loop overy my tableData and delete datas with 'alarm' then just load data and render table. But i can't do that becouse i have some dynamic datas so after render their disapear.
eveGrid.loadData(tableData);
eveGrid.render();
Dynamically hiding rows is quite a complex task which is not documented in the Handosntable documentation. However, there is plenty of functionality available to implement it ourselves. As a matter of fact, I had to do this just last week so I can share with you a potential approach. It's really quite simple and similar to your solution, which is not ugly by the way!
What you want to do is keep two copies of your data. The first we can call data, and the second activeData. Initially, they both equal each other. Now this part is tricky and not easy to grasp but what you have to make sure is that these two arrays are DIFFERENT OBJECTS, but have the SAME REFERENCED ELEMENTS. What this means is that the arrays themselves are not clones, so an equality test would fail. However, their elements are clones. Your activeData elements are just references to the elements on data.
Once we have this set up, it's simple to implement the hiding of rows. Your click should look through data and set a new activeData based on the matching rows you want to display. Then just update handsontable with something like:
hotInstance.updateSettings({data: activeData});
And that's it! Note that that updating method will automatically trigger a render().
Let me know how it goes, I'm curious to see if other people can use this approach.
Maybe this information is out there and my Google-fu is failing me, however I can't seem to find the answer. How can I get the number of rows being currently displayed in a jqGrid?
Every question and answer I've found on this topic tells you how to get either the total number of rows (displayed or not) or the number of rows loaded by an external service. Instead, I'm trying to get how many rows are being displayed in the current page of the jqGrid. One of my jqGrid attributes is rowList:[10,20,30], but I'm not sure how to access which one is selected myself.
All I want is how many rows are being currently dislpayed on each page of the jqGrid. The closest thing I've found so far has been this Q&A, but this displayed how many <tr>s there are and wasn't really what I needed.
$('.ui-pg-selbox').val()
Tested on the latest jqGrid (4.4.1)
Of course, if you have more than jqGrid per page, you can use an wrapper to ensure that it is the one you're looking for.
$('#myjqGridWrapper .ui-pg-selbox').val()
Not sure whether it's the best way, but it gets the job done.
The space means a descendant selector, that is it looks for elements containing the class ui-pg-selbox which are descendant of an wrapper #myjqGridWrapper. That would require having a div or some other wrapper around your table.
UPDATE: Also, if you have the table ID or a reference, you can use a more sturdy way of querying its jqGrid instance's .ui-pg-selbox:
$('#jqgridTableId').closest('.ui-jqgrid').find('.ui-pg-selbox').val()
The following will return you the number of displayed rows on a grid's page:
$('#myjqGridWrapper').getGridParam('reccount');
You shouldn't rely on the view for information. You should pull this information out of the JQGrid model. You can do so by calling the getGridParam method like so:
var rowNum = jqGrid.getGridParam('rowNum');
See here for more information: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
I am creating a dynamic table control with ASP.NET/C# and the table is being used to hold a form. I need to allow users to click on a button in a row and make a duplicate of that row right below the original. My page is also using AJAX and jQuery.
I have tried to use Table.Rows.AddAt(indexoforigrow+1, newrow) but I get an error that the index is out of the range of values. I figured maybe I wasn't getting the original row's index correctly so I just tossed in a 1 and still got the error.
I also noticed that when I press the button to execute the code, the table disappears. Any ideas on how to fix that?
I am thinking that if I am unable to get these issues fixed I will have to loop through the table and submit the data to a temp table, adding a new row where indicated. Then I would pull all of the data back out and display again.
EDIT
I moved on when I could not get this working and tried to setup my submit functions to loop through the data and submit it to a db and realized that I am experiencing the same issues when clicking the submit button as when I click the add row button. It appears that my issue is really with viewstates/postback.
I did some reading on this and from what I can tell the solution is to re-create the dynamic control on page load every time. But I am confused about how I can do this if I have no idea how many rows/cells I have and how is the information the user entered kept in the form? I have no way of saving the information to a DB or anything because as soon as submit is clicked it all disappears.
Have you considered using a different control? One of the grid controls might better serve your purpose.
I've handled situations (that sound) similar to what you're describing by using the footer of a GridView (among other ways). The big trick is to bind the display object (Table, GridView, etc.) to a list of objects. Then you manipulate the list of objects, rebinding the display object after the list has changed.
You will need to persist this list in some manner, or you could wind up with the list being reset to null. One way would be to save it as part of the session.
At any rate, the idea is to have a display object (GridView) bound to a list of objects. When the user clicks 'add', an item is added to the list. Save the list, then call the GridView.DataBind method.
You are on the right track with re-creating the dynamic table each time the page loads. I have dome similar things and my solution was to keep a client state in a hidden field on the page. Every time you add a row to the table on the client, increment a counter or adjust the state data in the hidden field. Then, on the server-when the page posts back, read from that hidden field to know how many rows were added on the client. You will have to use some kind of naming convention for the new rows you add(and the widgets in them) so you can re-create them on the server.
A simpler option may be to use an UpdatePanel. Rather than try to add the rows on the client, your "add row" button would cause a partial update. The server side code would add the new row to the table and the viewstate would be updated.
I ended getting my data guy to do a bit more processing on his end so that I could just bind a ListView to a sproc. Solved a few of my problems.
Thanks for the helpful comments.
Just returning to this almost a year later because I faced a similar issue in my current project. I was doing a few things wrong my first time around. First, I did indeed need to recreate the controls every load, but I also had to create them earlier in the page cycle. I was trying to create them during page load, which is after the viewstate is loaded.
The controls need to be recreated with the same ID before viewstate is loaded. I went with page init and it worked fine.