Set 'fitColumns' property to true and then call 'fitColumns' method. The datagrid will fit the grid width. Please try this code:
var width = $(window).width();
if (width>1000){
var dg = $(target);
var opts = dg.datagrid('options');
opts.fitColumns = true;
dg.datagrid('fitColumns');
}